Problem attaching debugger to running C++ app with embedded python


I'm trying to attach debugger to running C++ application which embeds the python, but it fails with "Connection to Python debugger failed: Accept timed out". Does anyone know what could be wrong?  Is this even supported?

I'm on Windows 7. The application is build using VS 2017.



Comment actions Permalink

No, I mean application does embed classic CPython. That is, you can use python scripts which are interpreted in application. Nothing fancy. And I want to debug the interpreted python code only.

None of the links provided are related to my problem.

Comment actions Permalink

Here is some "debug" log from script using to attach to process:

Attaching to a process with PID=10264
C:\Python36-32\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2019.2.2\helpers\pydev\pydevd_attach_to_process\" --port 64659 --pid 10264
Connecting to 32 bits target
Injecting dll
Dll injected
Allocating code in target process
Writing code in target process
Allocating return value memory in target process
Injecting code to target process
Waiting for code to complete

Process finished with exit code 0
Server stopped.
Comment actions Permalink

Anyone, please?

Comment actions Permalink

So after some debugging I found the culprit.

My application is single threaded and therefor the GIL is always acquired by the main thread. But because PyCharm debugger create new thread in my process and try to acquire the lock it isn't successful, because I never giveup the GIL (ok, this is not entirely true, because some internal py functions does release GIL for some operations and only then could PyCharm's debugger code be executed).

One option is to release/acquire the GIL on demand in my application but this isn't practical at all (a lot of interwinded code).

But I want to mention, that the Visual Studio PTVS *DOES* support debugging my application. So maybe PyCharm way of debugging isn't bulletproof and only is suitable for debugging the py programs run by python.exe or so.


Please sign in to leave a comment.