Debugger does not break when calling back from C created thread
ido-ran opened this issue · 3 comments
I have first open this bug in microsoft/vscode-python#14098 - but maybe here it's more appropriate.
Environment data
- Version: 1.49.0 (system setup)
- Commit: e790b931385d72cf5669fcefc51cdf65990efa5d
- Date: 2020-09-10T13:22:08.892Z
- Electron: 9.2.1
- Chrome: 83.0.4103.122
- Node.js: 12.14.1
- V8: 8.3.110.13-electron.0
- OS: Windows_NT x64 10.0.19041
- Extension version (available under the Extensions sidebar): v2020.8.109390
- Python version (& distribution if applicable, e.g. Anaconda): 3.8.0
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
- Relevant/affected Python packages and their versions: none
- Relevant/affected Python-related VS Code extensions and their versions: none
- Value of the
python.languageServer
setting: Jedi
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:
- Clone https://github.com/ido-ran/vscode-python-cthread-debugging
- Run
create-venv.sh
once to create venv - Run
build_thrd.sh
to build Cyton extension - Open
test_threading.py
in VS Code - Add breakpoint on the
print
statement inhandler
function - Start debug by pressing F5 or open the Run tab and click Start Debugging
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()
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
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.