microsoft / debugpy

An implementation of the Debug Adapter Protocol for Python
https://pypi.org/project/debugpy/
Other
1.74k stars 128 forks source link

VSCode sometimes stuck on breakpoint when debugging an embedded interpreter #1336

Open feeefeee opened 11 months ago

feeefeee commented 11 months ago

Before creating a new issue, please check the FAQ to see if your question is answered there.

Environment data

Actual behavior

When debugging a python script started from an interpreter embedded in a C++ app using pybind11, VSCode, sometimes refuses to continue execution with F5 after a breakpoint is hit. This behavior may occur after hitting 2 to 40 breakpoints.

Expected behavior

Always continue execution when hitting F5 after a breakpoint is hit

Steps to reproduce:

  1. Start an application with an interpreter embedded using pybind11
  2. Have the embedded interpreter execute the script to start debugging (debugging.py)

import debugpy

debugpy.log_to("c:/tmp") debugpy.configure({"python": "c:/Python/Python39/python.exe"}) debugpy.listen(5678)

print("Waiting for debugger to attach") debugpy.wait_for_client() print('Debugger attached')

  1. In VScode, start debug remote attach, the C++ apps resumes execution
  2. In VSCode open testing.py with

    print("starting") for i in range(10): print(i)

    print("done")

  3. Set breakpoints on the print('starting") and print('done') lines
  4. Have the C++ app execute testing.py
  5. In VScode, the first breakpoint is hit, press F5, the second breakpoint is hit
  6. Press F5 again, the C++ app continues the script, but VSCode remains stuck on the line with the last breakpoint hit

This is not strictly reproducible with two breakpoints. It can also occur after more than 40 breakpoints hit. This test was performed with PYDEVD_LOAD_NATIVE_LIB=0, but similar failures occured wythout this variable in the "real" application.

All code in https://github.com/feeefeee/debugpy11/tree/debugpy/1 Logs in https://github.com/feeefeee/debugpy11/tree/debugpy/1/logs/1

dBianchii commented 9 months ago

I think I am having this same issue. I have a typescript project that is now forever stuck on a breakpoint that I placed. Pressing F5 or clicking the continue button with my mouse does not do anything. This problem does not always happen, but only sometimes for me. It is really hindering my productivity though.

EDIT: Please let me know if I can do anyting to help investigate the issue. I am running on Ubuntu 20.04.06

EDIT2: Oh sorry, I thought that this issue was in VSCode Repo. So, unrelated to python/C++. I am using typescript. Maybe it isn't related to any language, but really a VScode issue?

bgolinvaux commented 2 days ago

I realized a funny thing when trying to debug Python scripts running in an embedded interpreter : unless you pass in_process_debug_adapter=True to debugpy.listen(...), debugpy will try to launch the executable found at _config.get("python", sys.executable) which, in the embedded scenario, is not Python but the actual executable (C++ in my case). debugpy assumes that it's Python or at least that it's able to launch Python scripts passed in arguments.

Even though it did not work (obviously), my breakpoint was still hit, but debugging did not really work.

Can you maybe try to check that you are using an in-process adapter by specifying this flag?

(Beware: using in-process adapters seemingly preclude the debugging of sub-processes but, when using embedded Python, I guess launching subprocesses also running Python is a rare occurrence)