Commit 07d6226
committed
gh-140746: Fix Thread.start() hanging when the thread dies during bootstrap
If the new thread dies before _bootstrap_inner() reaches self._started.set()
(e.g. a MemoryError raised while calling _bootstrap under memory pressure, or
a silently-cleared SystemExit), the parent thread waits forever in
Thread.start() and the dead thread lingers in threading._limbo.
Add a C-level thread_started PyEvent to ThreadHandle, notified by the thread
right after it sets _started and unconditionally by thread_run() on exit
(covering a failed bootstrap call, SystemExit, and the finalization early
exit). Thread.start() now waits on this event instead of the Python-level
event alone and raises RuntimeError if the thread terminated before
signalling startup.1 parent 93beea7 commit 07d6226
5 files changed
Lines changed: 121 additions & 2 deletions
File tree
- Doc/library
- Lib
- test
- Misc/NEWS.d/next/Core_and_Builtins
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
570 | | - | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
571 | 574 | | |
572 | 575 | | |
573 | 576 | | |
| |||
576 | 579 | | |
577 | 580 | | |
578 | 581 | | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
579 | 586 | | |
580 | 587 | | |
581 | 588 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1505 | 1505 | | |
1506 | 1506 | | |
1507 | 1507 | | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
1508 | 1557 | | |
1509 | 1558 | | |
1510 | 1559 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1144 | 1144 | | |
1145 | 1145 | | |
1146 | 1146 | | |
1147 | | - | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
1148 | 1162 | | |
1149 | 1163 | | |
1150 | 1164 | | |
| |||
1205 | 1219 | | |
1206 | 1220 | | |
1207 | 1221 | | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
1208 | 1225 | | |
1209 | 1226 | | |
1210 | 1227 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
149 | 157 | | |
150 | 158 | | |
151 | 159 | | |
| |||
232 | 240 | | |
233 | 241 | | |
234 | 242 | | |
| 243 | + | |
235 | 244 | | |
236 | 245 | | |
237 | 246 | | |
| |||
323 | 332 | | |
324 | 333 | | |
325 | 334 | | |
| 335 | + | |
326 | 336 | | |
327 | 337 | | |
328 | 338 | | |
| |||
409 | 419 | | |
410 | 420 | | |
411 | 421 | | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
412 | 428 | | |
413 | 429 | | |
414 | 430 | | |
| |||
708 | 724 | | |
709 | 725 | | |
710 | 726 | | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
711 | 749 | | |
712 | 750 | | |
713 | 751 | | |
| |||
741 | 779 | | |
742 | 780 | | |
743 | 781 | | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
744 | 785 | | |
745 | 786 | | |
746 | 787 | | |
| |||
0 commit comments