microsoft / ptvsd

Python debugger package for use with Visual Studio and Visual Studio Code.
Other
548 stars 68 forks source link

Debugger does not break when calling back from C created thread #2137

Closed ido-ran closed 4 years ago

ido-ran commented 4 years ago

I have first open this bug in https://github.com/microsoft/vscode-python/issues/14098 - but maybe here it's more appropriate.

Environment data

Expected behaviour

The debugger will break on the breakpoint set in VS Code.

Actual behaviour

The debugger does not break on the breakpoint set.

Steps to reproduce:

  1. Clone https://github.com/ido-ran/vscode-python-cthread-debugging
  2. Run create-venv.sh once to create venv
  3. Run build_thrd.sh to build Cyton extension
  4. Open test_threading.py in VS Code
  5. Add breakpoint on the print statement in handler function
  6. Start debug by pressing F5 or open the Run tab and click Start Debugging
fabioz commented 4 years ago

This is a known issue...

We already tried some approaches and still haven't been able to come up with a good solution to do that in the general case, so, for now, you're required to manually ask for non-python started threads to be traced.

To do that you can use the following api:

import debugpy
debugpy.debug_this_thread()
ido-ran commented 4 years ago

Thanks @fabioz. I've added this call into my pyx file and that is solving the problem in VS Code. I actually need to make it work in PyCharm as well, using this snippet seems to cover all bases as both PyCharm and VS Code are using pydev under the hood:

    try:
        import pydevd
        pydevd.settrace(suspend=False)
    except:
        # ignore if debugger is not available
        pass
fabioz commented 4 years ago

Yeap, using the pydevd api directly should also work for debugpy ;)

p.s.: I'm closing as this is a known issue which is being tracked elsewhere.