Process creation after debugging session not possible: teardown needed
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 70/100
Research direction
Start in debugpy._vendored.pydevd.pydevd at stoptrace() and inspect how patch_new_process_functions() replaces _winapi.CreateProcess. Reproduce the issue with the provided subprocess.Popen example after teardown, then verify that process creation works again after teardown without restarting the program.
Written by the indexing model from the issue text.
Description
Environment data
- debugpy version: latest
- OS and version: Windows 11
- Python version 314 (but issue is not python-version related)
- Using VS Code
Actual behavior
Connect to VSCode. Then apply
test = subprocess.Popen(
["C:\Python314\python.exe", "-c", "import sys; sys.exit(0)"],
creationflags=creationflags,
)
test.wait()
print(test.returncode)
this does not work because subprocess was patched. Also not after teardown of the debugging session:
from debugpy._vendored.pydevd.pydevd import stoptrace
stoptrace() to continue running the process. Now, subprocess.popen() does not work any more at al.
.... still subprocess.Popen will not work
Expected behavior
subprocess.Popen() should work
Steps to reproduce:
After debugging started, the following won't work. Make sure NOT to issue
debugpy.configure(subProcess=False) in order to reproduce this:
test = subprocess.Popen(
["C:\Python314\python.exe", "-c", "import sys; sys.exit(0)"],
creationflags=creationflags,
)
test.wait()
print(test.returncode)
SOLUTION
pydevd's patch_new_process_functions() patches _winapi.CreateProcess to intercept child process creation for subprocess debugging, but stoptrace() never unpatches it.
The effect is that you can't spawn processes after a debugging session is torn down and you want to resume your program without restart. The solution is a restoration on teardown:
from debugpy._vendored.pydevd.pydevd import stoptrace
stoptrace()
debugpy.server.api.listen.called = False # reset state so it can reconnect later
try:
import _winapi as _subprocess
except ImportError:
import _subprocess
if hasattr(_subprocess, 'original_CreateProcess'):
_subprocess.CreateProcess = _subprocess.original_CreateProcess
del _subprocess.original_CreateProcess
- Dominant language
- Python
- Stars
- 2.5k
- Forks
- 202
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/debugpy
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
All issues in microsoft/debugpy
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
canonical/paas-charm#368 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
tech debt
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
StevenBlack/hosts#3256 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
qualcomm/qai-appbuilder#275 ·