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

Support gevent 20.12.1 #515

Closed
plenzjr opened this issue Jan 5, 2021 · 11 comments
Closed

Support gevent 20.12.1 #515

plenzjr opened this issue Jan 5, 2021 · 11 comments
Labels
enhancement New feature or request

Comments

@plenzjr
Copy link

plenzjr commented Jan 5, 2021

Environment data

  • VS Code version: 1.52.1
  • OS and version: Ubuntu 20.04
  • Python version: 3.8.5
  • Type of virtual environment used: venv
  • Relevant/affected Python packages and their versions: Flask, gevent
  • Relevant/affected Python-related VS Code extensions and their versions: Python, v2020.12.424452561,
  • Debugpy version: 1.2.1

Actual behavior

Running the app from the debug console doesn't stop in some breakpoints and a warning is printed.

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"
            },
            "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)
@int19h
Copy link
Contributor

int19h commented Jan 5, 2021

If you're using gevent, you need to tell the debugger so that it tries to play nice with it:

"gevent": true

@fabioz
Copy link
Collaborator

fabioz commented Jan 5, 2021

Closing since it's expected that things don't work if "gevent": true is not specified in the launch configuration when using gevent.

Feel free to reopen if you find any issues when running with the gevent flag set.

@fabioz fabioz closed this as completed Jan 5, 2021
@plenzjr
Copy link
Author

plenzjr commented Jan 5, 2021

Its set up on my env var, I just forget to add in this example

@fabioz fabioz reopened this Jan 5, 2021
@fabioz
Copy link
Collaborator

fabioz commented Jan 5, 2021

Reopening then... can you provide the logs for the run?

i.e.:

  • Open VS Code
  • Select the command Extensions: Open Extensions Folder
  • Locate the Python extension directory, typically of the form ms-python.python-2020..***
  • In that directory ensure you do not have any debug*.log files, if you do, please delete them
  • Go back into VS Code and modify your launch.json to add the setting "logToFile": true
  • Start debugging
  • When done, go back into the extension directory and upload the debug*.log files into this GitHub issue.

@fabioz
Copy link
Collaborator

fabioz commented Jan 5, 2021

I took a quick look at: https://github.com/gevent/gevent/blob/master/src/gevent/threadpool.py and it seems that gevent is now starting to call sys.settrace directly (this was added very recently in: gevent/gevent@5a05e82).

So, some work is probably needed on the debugger now that gevent is messing with the tracing that the debugger uses.

@plenzjr
Copy link
Author

plenzjr commented Jan 5, 2021

you are right,
gevent version 20.12.1 is causing the issue.
downgrade to the version 20.9.0 and run it without any problem.

thank you!

@plenzjr plenzjr closed this as completed Jan 5, 2021
@fabioz fabioz reopened this Jan 5, 2021
@fabioz
Copy link
Collaborator

fabioz commented Jan 5, 2021

I'll keep it open since we should support the newer release in the future...

@fabioz fabioz changed the title Running flask app with gevent rises warning and some breakpoints doesn't work Support gevent 20.12.1 Jan 5, 2021
@karthiknadig karthiknadig added the enhancement New feature or request label Jan 6, 2021
@jwilges
Copy link

jwilges commented Aug 3, 2021

@fabioz you mentioned this ticket as the way to track progress for newer gevent support in #189. Is this now the central ticket for us to track if we are looking to find out when newer gevent releases (e.g. 21 and above) are supported?

Thanks for all of the digging you've done to uncover the root(s) of the problem. Your analysis in #189 was enlightening.

@furgoose
Copy link

I've tried out the version mentioned here, 20.12.1, and the latest, 21.12.0 but both seem to still produce the error so not sure if this has been fixed?

@brdacost
Copy link

I've tried out the version mentioned here, 20.12.1, and the latest, 21.12.0 but both seem to still produce the error so not sure if this has been fixed?

tried with version 21.12.0 on macos intel, and it is still not stopping on breakpoints

@calenjackman
Copy link

I'm having a similar issue with gevent==21.12.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants