Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Process creation after debugging session not possible: teardown needed

Open
#2,014 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
devtools

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/debugpy

All issues in microsoft/debugpy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.