Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug does not work with new Python Gevent/Greenlet versions #1126

Closed
plenzjr opened this issue Nov 14, 2022 · 7 comments
Closed

Debug does not work with new Python Gevent/Greenlet versions #1126

plenzjr opened this issue Nov 14, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@plenzjr
Copy link

plenzjr commented Nov 14, 2022

Environment data

  • VS Code version: 1.73.0
  • OS and version: Ubuntu 20.04
  • Python version: 3.8.10
  • Type of virtual environment used: venv
  • Relevant/affected Python packages and their versions: Flask==2.2.2, Gevent==20.9.0

Actual behavior

Already reported this issue in #515 but seems still broke

Running the app from the debug console doesn't stop in any breakpoints and a warning is printed.
Gevent installs greenlet==2.0.1, that seems to be the main problem. Installed greenlet==1.1.3 and it works

Expected behavior

Stop in all breakpoints and resolve warnings

Steps to reproduce:

  • setup a virtualenv

    1. python3 -m ./.venv example
    2. source ./.venv/bin/activate
  • install packages

    1. python3 -m pip install flask gevent
  • create file run.py

from gevent import monkey
monkey.patch_all()


from flask import Flask
from datetime import datetime
import re


app = Flask(__name__)


@app.route("/")
def home():
    print('start')
    print('set a breakpoint')
    print('should stop')
    return "Hello, Flask!"


@app.route("/hello/<name>")
def hello_there(name):
    now = datetime.now()
    formatted_now = now.strftime("%A, %d %B, %Y at %X")

    # Filter the name argument to letters only using regular expressions. URL arguments
    # can contain arbitrary text, so we restrict to safe characters only.
    match_object = re.match("[a-zA-Z]+", name)

    if match_object:
        clean_name = match_object.group(0)
    else:
        clean_name = "Friend"

    content = "Hello there, " + clean_name + "! It's " + formatted_now
    return content


if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5100, debug=True, threaded=True, use_reloader=False)
  • configure files:
    1. launch.json
{
    "configurations": [
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "module": "flask",
            "cwd": "${workspaceRoot}",
            "env": {
                "FLASK_APP": "run.py",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "0",
                "GEVENT_SUPPORT": 1,
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload",
                "--port=5100"
            ],
            "jinja": true,
            "console": "integratedTerminal",
            "justMyCode": false
        }
    ]
}
  1. settings.json
{
    "python.pythonPath": "${env:HOME}/.venv/example/bin/python",
}

Run from debug

Logs

  • logs from console
PYDEV DEBUGGER WARNING:
sys.settrace() should not be used when the debugger is being used.
This may cause the debugger to stop working correctly.
If this is needed, please check: 
http://pydev.blogspot.com/2007/06/why-cant-pydev-debugger-work-with.html
to see how to restore the debug tracing back correctly.
Call Location:
  File "${HOME}/.venv/example/lib/python3.8/site-packages/gevent/threadpool.py", line 157, in _before_run_task
    _sys.settrace(_get_thread_trace())


PYDEV DEBUGGER WARNING:
sys.settrace() should not be used when the debugger is being used.
This may cause the debugger to stop working correctly.
If this is needed, please check: 
http://pydev.blogspot.com/2007/06/why-cant-pydev-debugger-work-with.html
to see how to restore the debug tracing back correctly.
Call Location:
  File "${HOME}/.venv/example/lib/python3.8/site-packages/gevent/threadpool.py", line 162, in _after_run_task
    _sys.settrace(None)
@fabioz
Copy link
Collaborator

fabioz commented Nov 16, 2022

As a note, the newer greenlet (2.0.1) was released on November 7th, so, this matches the date that we started receiving reports of the breakage (https://pypi.org/project/greenlet/#history) -- it may be related to the Mac OS failure related gevent in the CI too.

The solution right now is keeping to greenlet 1.1.3 until we can check that we can fix this in the debugger side (possibly this needs to be fixed in the greenlet side too, I still need to investigate as a failing assert for the trace function REFCNT seems a bit strange in the first place).

int19h pushed a commit to int19h/debugpy that referenced this issue Nov 16, 2022
@int19h int19h added the bug Something isn't working label Nov 16, 2022
@fabioz
Copy link
Collaborator

fabioz commented Nov 17, 2022

There seem to be 2 issues lying around with the latest release:

One of them is the assertion failure (I think this is probably fixable only in greenlet... I reported python-greenlet/greenlet#332 to track that).

The other one is the tracing warning... I probably need to adapt the code in the debugger to handle that properly, but it seems that I still have issues with greenlets missing breakpoints with the latest version of gevent, so, this will need more investigation on my side (gevent seems to be unsetting the tracing function).

@alexdauenhauer
Copy link

hi this is not fixed for me. I am still getting this error

Assertion failed: (this->tracefunc.REFCNT() == old_refs + 1), function set_tracefunc, file greenlet_thread_state.hpp, line 314.

when I try to debug tests

@int19h
Copy link
Contributor

int19h commented Feb 3, 2023

As noted earlier, the assert itself was incorrect as written, and needs to be fixed on the greenlet side - this was python-greenlet/greenlet#332. It looks like they have just fixed it a few days ago, and that shipped in greenlet 2.0.2 - can you make sure that you're using that version?

@alexdauenhauer
Copy link

@int19h ah ok greenlet 2.0.2 seems to resolve it. Thank you!

@nmz787-intel
Copy link

nmz787-intel commented Oct 9, 2023

issue persists for me with gevent 23.9.1 and greenlet 3.0.0.
It appears the offending line of code has been unmodified here https://github.com/gevent/gevent/blob/master/src/gevent/threadpool.py#L163

@stampycode
Copy link

Issue persists for me with gevent 24.2.1 and greenlet 3.0.3.

Call Location:
  File "/usr/local/lib/python3.12/site-packages/gevent/threadpool.py", line 163, in _before_run_task
    _sys.settrace(_get_thread_trace())
Call Location:
  File "/usr/local/lib/python3.12/site-packages/gevent/threadpool.py", line 168, in _before_run_task
    _sys.settrace(_get_thread_trace())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants