Repository navigation
Description
What the caller sees
A Python program with two threads, each with a breakpoint on its path. After some number of continue_execution calls, wait_for_stop answers pending: true and keeps doing so. The session's state is running. The program is not running: both threads are suspended on their breakpoint lines, and their own output stops.
pause_execution gets out of it. About 0.5 s later a stop arrives with reason pause, and the stack shows the thread on its breakpoint line.
What happens
On the wire, the last frames before the silence are ordinary:
out request continue {"threadId":2}
in response continue {"allThreadsContinued":true}
in event continued {"threadId":2,"allThreadsContinued":true}
(nothing for 10 s, until the caller's pause)
debugpy's own log for that moment, in every session that froze:
Resuming threads: * (except thread: None)
Leaving PyDB.do_wait_suspend: <Thread(workerA, ...)>
Leaving PyDB.do_wait_suspend: <Thread(workerB, ...)>
Suspending all threads except: <Thread(workerA, ...)>
Suspending all threads except: <Thread(workerB, ...)>
PyDB.do_wait_suspend
PyDB.do_wait_suspend
Suspend not sent because stop reason is thread suspend and pause was not requested.
Suspend not sent because stop reason is thread suspend and pause was not requested.
Both threads reach their breakpoints together. Each one suspends "all other threads", and that overwrites the other thread's stop reason with "thread suspend" (mark_thread_suspended in pydevd_thread_lifecycle.py assigns thread.stop_reason) before the other thread has read its own reason in do_wait_suspend. Each then finds "thread suspend" and announces nothing.
The server is told nothing, so "running" is what it observed.
Measured
Main at f08a5158, Python 3.13.12, debugpy 1.8.20, Windows 11, an attach session, through the server over stdio. Two worker threads, each looping over its own breakpoint line with a 3 ms sleep.
- Eight of eleven sessions froze this way, after 26 to 204 rounds. The three shapes of the loop were:
continue_executionthenwait_for_stop; the same with aget_stack_traceafter the resume; the same with a secondcontinue_executionsent during the landing read. - All eight logs show the two "Suspend not sent" lines after the last resume, and no "Sending suspend notification".
- In all eight, the stop that
pause_executionproduced found its thread on the breakpoint line.
Two conditions to know when reading that rate:
- debugpy's debug log was on inside the program in those sessions (
DEBUGPY_LOG_DIRwas set for the program, which is what our adapter did for every launch until python: the adapter sets DEBUGPY_LOG_DIR for every session, so debugpy's debug log runs inside the program (a log line per logpoint hit, on the hitting thread) #1264 was fixed). With it off, the two shapes that froze most ran 300 rounds each with no freeze. That does not show the log matters for the race. A freeze needs both threads at their breakpoints together, so what counts is how often the second thread got there: with the log on it completed 15 loop iterations across the eight sessions and 6 ended in a freeze; with the log off it completed 4 and none did. Six of fifteen against none of four cannot be told apart (Fisher's exact test, p about 0.18). What the runs do show is that the second thread got to run about four times as often with the log on, so per round the log-on runs froze more often (6 in 600 against 0 in 600). That is a fact about this harness's loop. The two runs also differed in harness version and were an hour apart. The run that would settle it puts both threads on their breakpoint lines every round, with the log on and off; it has not been done. - A tight loop over a breakpoint is not how an agent debugs. The shape that matters is an ordinary one, though: a breakpoint in a function that several pool threads run at once.
A second thing the same traces show
After continue answered allThreadsContinued: true, the second thread usually did not resume. In each of the thirteen sessions, the first thread left its wait at every resume (28 to 301 of them) and the second left its wait 2 to 11 times. The second thread's own journal ended at 1 to 5 lines while the first's reached 28 to 299. In the log, the first thread's next "Suspending all threads except" follows its own "Leaving PyDB.do_wait_suspend" with no "Leaving" for the second thread between them. This part does not depend on the log: with it off, the second thread's journal ended at 1 and 3 lines in 300 rounds.
Upstream
microsoft/debugpy#2048 ("debugpy becomes unresponsive after rapid breakpoint suspend/resume cycles in multithreaded Python programs") describes the same symptom. It was closed on 2026-10-08 by a fix that is in no release yet (the newest release is 1.8.22). That fix changes the notification bookkeeping in pydevd.py; mark_thread_suspended is in a file it does not touch. The repro above has not been run against it.
What can be done here
- Build a target that puts both threads on their breakpoint lines every round, and run it with debugpy's in-program log on and off, and against debugpy's main. That says how often the race fires, whether the log matters, and whether their fix for issue 2048 covers it. If it does not, it needs an upstream report with a fix.
- python: the adapter sets DEBUGPY_LOG_DIR for every session, so debugpy's debug log runs inside the program (a log line per logpoint hit, on the hitting thread) #1264 is fixed (fix(python): stop turning debugpy's debug log on inside the debugged program #1392): a launched program no longer runs with debugpy's debug log on. Whether that changes how often this freeze happens is not known (see the first condition above).
- A
wait_for_stopthat answerspendingcannot know the program is frozen. It can say what does tell:pause_executionshows where each thread is.
Where it was found
While measuring the precondition of #1348 with real engines. The measurement's driver treated these sessions as stalls and restarted; the freeze itself is the finding.
Activity
debugmcpdev commentedon Nov 29, 2026
The part of this that is ours is merged: #1392 stops the adapter turning debugpy's debug log on inside a launched program (closes #1264). In the measurement above, that log is what made the freeze frequent: 6 freezes in 600 rounds with it on, none in 600 with it off.
What stays open here:
--log-toorDEBUGPY_LOG_DIRhas the old exposure.wait_for_stopthat answerspendingstill says nothing aboutpause_executionbeing the way to see where each thread is.debugmcpdev commentedon Nov 30, 2026
Correction to what I wrote here about the freeze of #1384. I said that debugpy's in-program log is what made that freeze frequent ("6 freezes in 600 rounds with it on, none in 600 with it off"). The comparison does not show that.
A freeze needs both threads at their breakpoints together, so what counts is how often the second thread got there. With the log on it completed 15 loop iterations across the eight sessions, and 6 of them ended in a freeze. With the log off it completed 4, and none did. Six of fifteen against none of four cannot be told apart (Fisher's exact test, p about 0.18).
What the runs do show is narrower. Per round, the log-on runs froze more often (6 in 600 against 0 in 600), because the second thread got to run about four times as often with the log on. That is a fact about this harness's tight loop, not about the race. The two runs also differed in more than the log: the harness version, an hour between them, and the power state, which was recorded for one only.
What stands is the cost of a logpoint hit (26.1 µs with the log, 11.7 µs without), which is what #1264 was about. Whether the log changes how often the freeze happens is open, and #1384 says so. The changelog entry and two code comments carried the same claim; #1397 corrects them.
(Edited once: my first version of this correction compared loop iterations on one side with wait exits on the other, which made the gap look larger than it is.)