Commit 02c895e
Run service-thread event loops on a selector loop on Windows
When the kernel runs under a ProactorEventLoop on Windows (enabled by
gh-1469 so the main loop can spawn asyncio subprocesses, gh-1468),
debugging deadlocks on Python >= 3.12.
ProactorEventLoop has no native add_reader, so tornado drives a Proactor
loop's zmq sockets via a helper "Tornado selector" thread that does
select() then call_soon_threadsafe() to wake the loop. ipykernel exempts
its own service threads from the debugger but not tornado's helper. When
debugpy suspends every thread at a breakpoint under sys.monitoring
(3.12+, interpreter-global), that un-exempt helper freezes mid-wake and
the control/debug read path never advances -- the loop sits in the IOCP
poll forever. On 3.11 (sys.settrace, per-thread) the helper is not frozen,
so it does not reproduce there.
The ipykernel service loops -- control, IOPub, the shell channel and
subshells -- never need Proactor's subprocess support, so run them on a
SelectorEventLoop instead: it implements add_reader natively and needs no
helper thread. Only the main/user-code loop stays on Proactor. Off Windows
the default loop is already selector-based, so this is a no-op there.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 6a75d0f commit 02c895e
2 files changed
Lines changed: 28 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
| 27 | + | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | | - | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
11 | 35 | | |
12 | 36 | | |
13 | 37 | | |
14 | 38 | | |
15 | 39 | | |
16 | 40 | | |
17 | | - | |
| 41 | + | |
18 | 42 | | |
19 | 43 | | |
20 | 44 | | |
| |||
0 commit comments