Breakpoints don't work in threads created after `debugpy.listen()` is called
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 52/100
調査の方向性
まず、提供されている再現用 multithread_debugging.py を start_listener_at_index=5 で実行し、GUI ブレークポイントと breakpoint() を比較します。debugpy.listen() 周辺のスレッド設定を追跡します。完了条件は、期待される動作どおり、listen の前後に開始されたスレッドの両方で GUI ブレークポイントに到達することです。
索引モデルが issue の本文から書いたものです。
説明
Environment data
- debugpy version: 1.8.14 / 1.8.17
- OS and version: Mac OS 15.6.1
- Python version (& distribution if applicable, e.g. Anaconda): 3.10.12
- Using VS Code or Visual Studio: Visual Studio Code Version: 1.104.1
Actual behavior
In threads which are started (via threading.Thread.start()) after the call to debugpy.listen(), breakpoints will not work.
Expected behavior
Breakpoints should work in all threads, regardless of when they are started.
Steps to reproduce:
- Use the following script:
# multithread_debugging.py
import sys
import threading
from queue import Queue
import debugpy
threads: list[threading.Thread] = []
queues: list[Queue] = []
N_THREADS = 10
POISON_PILL = -1
def handler(q: Queue):
while True:
item = q.get()
print(threading.current_thread(), item)
if item == POISON_PILL:
print(threading.current_thread(), "exiting")
return
def send(i: int, item):
queues[i].put(item)
def end(i: int, *, wait=False):
send(i, POISON_PILL)
if wait:
threads[i].join()
def end_all():
for i in range(N_THREADS):
end(i)
for t in threads:
t.join()
print("all done")
if __name__ == "__main__":
start_listener_at_index = 0
if len(sys.argv) >= 2:
start_listener_at_index = int(sys.argv[1])
for i in range(10):
q = Queue()
t = threading.Thread(target=handler, args=[q])
threads.append(t)
queues.append(q)
for i, t in enumerate(threads):
if i == start_listener_at_index:
print(f"starting debug listener before thread {i} starts")
debugpy.listen(("0.0.0.0", 5680))
t.start()
- Add the following launch configuration:
{
"name": "Attach to multithreading example",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5680
}
},
- Run
python -i multithread_debugging.py 5 - Add a breakpoint on the print statement in the
handler()method. - Run the "Attach to multithreading example" debug configuration.
- In the REPL, run:
send(0, "foo"). Note that the breakpoint is not triggered. - In the REPL, run:
send(4, "foo"). Note that the breakpoint is not triggered. - In the REPL, run
send(5, "foo"). Note that the breakpoint IS triggered (because thread 5 is started after the debugpy listen call).
Further notes
If you set the breakpoint using the breakpoint() function, it works in all threads. However, if you set it using the vscode GUI, you get the buggy behaviour described above.
- 主要言語
- Python
- スター
- 2.5k
- フォーク
- 202
- 平均マージ
- 5日 1時間
- マージ済み PR(30日)
- 1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/debugpy のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
microsoft/debugpy の issue をすべて見る
似ている issue
-
bug confirmed issue
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
open-webui/open-webui#30750 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 90/100