PyDev.Debugger icon indicating copy to clipboard operation
PyDev.Debugger copied to clipboard

Debugging script running in embedded interpreter via remote attach not working without PYDEVD_LOAD_NATIVE_LIB=0

Open emonette123 opened this issue 6 months ago • 0 comments

This relates to debugging scripts running in embedded interpreters. In my experience, breakpoints will not be hit if you use the standard approach in VS Code, ie, have a script running in the embedded interpreter having this:

if not debugpy.is_client_connected():
    debugpy.configure(python=r"D:\NXOpen\sandbox\training\py\setup\.venv\nx2312\Scripts\python.exe")
    debugpy.listen(5678)
    print("Waiting for debugger to attach...")
    debugpy.wait_for_client()

debugpy.breakpoint()
to_listing_window("One line")

Run the script in the embedded interpreter, start debugging with VS Code remote attach. The script will exit the debugpy.wait_for_client() call, but it will then run to completion, without breaking.

If you define the weird environment variable PYDEVD_LOAD_NATIVE_LIB=0, it works properly. For both programmatic breakpoints and breakpoints set in VS Code.

To me, this should be part of the configuration as I always have a hard time finding back the information about that magical environment variable, which only job seems to not spawn tracing over all threads.

Can you add a configuration key like using_embedded_interpreter and just behave as if PYDEVD_LOAD_NATIVE_LIB=0 was set in the environment? This key should also enforce people to define the python key in the configuration because if you do not, the debugger will launch another instance of the app embedding the interpreter (sys.executable is NOT python when using an embedded interpreter).

emonette123 avatar Feb 20 '24 22:02 emonette123