Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Process creation after debugging session not possible: teardown needed

オープン
#2,014 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python
領域
devtools

調査の方向性

debugpy._vendored.pydevd.pydevd の stoptrace() から始め、patch_new_process_functions() が _winapi.CreateProcess をどのように置き換えているかを調べます。teardown 後に、提供された subprocess.Popen の例で問題を再現し、その後、プログラムを再起動せずに teardown 後のプロセス作成が再び機能することを確認します。

索引モデルが issue の本文から書いたものです。

説明

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		
主要言語
Python
スター
2.5k
フォーク
202
平均マージ
5日 1時間
マージ済み PR(30日)
1

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/debugpy のほかの issue

microsoft/debugpy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。