question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for gevent in ptvsd

See original GitHub issue

Currently ptvsd cannot run in a gevent/greenlet script, it just hungs:

from gevent import monkey
monkey.patch_all()
import ptvsd

ptvsd.enable_attach("test", address=('0.0.0.0', 3000))
ptvsd.wait_for_attach()
ptvsd.break_into_debugger()

It would be great if we could debug gevent apps.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
layzerarcommented, Sep 15, 2018

I think this script should work for most users, cheers.

from gevent import monkey
monkey.patch_all()

def setup_ptvsd(host='0.0.0.0', port=5678):
    import sys
    saved_modules = {}
    try:
        green_modules = set([
            'socket', 'ssl', 'select', 'urllib',
            'thread', 'threading', 'time', 'logging',
            'os', 'signal', 'subprocess', 'requests',
        ])
        for modname in list(sys.modules.keys()):
            if modname.partition('.')[0] in green_modules:
                saved_modules[modname] = sys.modules.pop(modname)

        import ptvsd
        ptvsd.enable_attach(address=(host, port), redirect_output=False)
    finally:
        sys.modules.update(saved_modules)

setup_ptvsd()
1reaction
cyberwcommented, Jul 15, 2019

I found this: https://github.com/Microsoft/vscode-python/issues/127

Adding "gevent": true to my launch config made it work again! (with the layzerar’s workaround still applied)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Support for gevent in ptvsd -
Currently ptvsd cannot run in a gevent/greenlet script, it just hungs: from gevent import monkey monkey.patch_all() import ptvsd ptvsd.enable_attach("test", ...
Read more >
Debugging configurations for Python apps in ...
The Python extension supports debugging of several types of Python applications. ... If set to true , enables debugging of gevent monkey-patched code....
Read more >
How does one use the VSCode debugger to debug a ...
Add the following code into your routerservice_config.py (or similar python startup file) import ptvsd ptvsd.enable_attach("my_secret", ...
Read more >
Visual Code debug requirement GEVENT_SUPPORT=True
I was asked to create a global variable GEVENT_SUPPORT=True. Is gevent a mandatory requirement ... to enable gevent support in the debugger.
Read more >
Remotely debug a Python app inside a Docker container in ...
Visual Studio Code supports ptvsd 4 now! ... -p '*.py' -R -- celery -A app:celery worker --pid= -P gevent --without-gossip ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found