Commit 89d8bbe
Rémy Voet (ryv)
gh-140746: Fix Thread.start() can hang forever
When a new thread is started (`Thread.start()`), the current thread
waits for the new thread's `_started` signal (`self._started.wait()`).
If the new thread doesn't have enough memory, it might crash before
signaling its start to the parent thread, causing the parent thread
to wait indefinitely (still in `Thread.start()`).
To fix the issue, remove the _started python attribute from the
Thread class and converted the logic at C level (PyEvent).
A flaw of this method, it that the threading module will still
contains the zombie thread into the _limbo dictionnary.
We also change `Thread._delete()` to use `pop` to remove the thread from
`_active`, as there is no guarantee that the thread exists in
`_active[get_ident()]`, thus avoiding a potential `KeyError`.
This can happen if `_bootstrap_inner` crashes before
`_active[self._ident] = self` executes. We use `self._ident` because we
know `set_ident()` has already been called.
Moreover, remove the old comment in `_delete` because
`_active_limbo_lock` became reentrant in commit.
243fd01.1 parent 909f76d commit 89d8bbe
File tree
4 files changed
+60
-24
lines changed- Lib
- test
- Misc/NEWS.d/next/Core_and_Builtins
- Modules
4 files changed
+60
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | 218 | | |
224 | 219 | | |
225 | 220 | | |
| |||
228 | 223 | | |
229 | 224 | | |
230 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
231 | 232 | | |
232 | 233 | | |
233 | 234 | | |
| |||
307 | 308 | | |
308 | 309 | | |
309 | 310 | | |
310 | | - | |
| 311 | + | |
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
| |||
1457 | 1458 | | |
1458 | 1459 | | |
1459 | 1460 | | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
1460 | 1487 | | |
1461 | 1488 | | |
1462 | 1489 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
930 | 930 | | |
931 | 931 | | |
932 | 932 | | |
933 | | - | |
934 | 933 | | |
935 | 934 | | |
936 | 935 | | |
| |||
940 | 939 | | |
941 | 940 | | |
942 | 941 | | |
943 | | - | |
944 | 942 | | |
945 | 943 | | |
946 | 944 | | |
| |||
955 | 953 | | |
956 | 954 | | |
957 | 955 | | |
958 | | - | |
| 956 | + | |
959 | 957 | | |
960 | 958 | | |
961 | 959 | | |
| |||
978 | 976 | | |
979 | 977 | | |
980 | 978 | | |
981 | | - | |
| 979 | + | |
982 | 980 | | |
983 | 981 | | |
984 | 982 | | |
| |||
1001 | 999 | | |
1002 | 1000 | | |
1003 | 1001 | | |
1004 | | - | |
1005 | 1002 | | |
1006 | 1003 | | |
1007 | 1004 | | |
| |||
1061 | 1058 | | |
1062 | 1059 | | |
1063 | 1060 | | |
1064 | | - | |
1065 | 1061 | | |
1066 | 1062 | | |
1067 | 1063 | | |
| |||
1081 | 1077 | | |
1082 | 1078 | | |
1083 | 1079 | | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
| 1080 | + | |
1089 | 1081 | | |
1090 | 1082 | | |
1091 | 1083 | | |
| |||
1113 | 1105 | | |
1114 | 1106 | | |
1115 | 1107 | | |
1116 | | - | |
| 1108 | + | |
1117 | 1109 | | |
1118 | 1110 | | |
1119 | 1111 | | |
| |||
1176 | 1168 | | |
1177 | 1169 | | |
1178 | 1170 | | |
1179 | | - | |
| 1171 | + | |
1180 | 1172 | | |
1181 | 1173 | | |
1182 | 1174 | | |
| |||
1199 | 1191 | | |
1200 | 1192 | | |
1201 | 1193 | | |
1202 | | - | |
| 1194 | + | |
1203 | 1195 | | |
1204 | 1196 | | |
1205 | 1197 | | |
| |||
1385 | 1377 | | |
1386 | 1378 | | |
1387 | 1379 | | |
1388 | | - | |
1389 | 1380 | | |
1390 | 1381 | | |
1391 | 1382 | | |
| |||
1433 | 1424 | | |
1434 | 1425 | | |
1435 | 1426 | | |
1436 | | - | |
1437 | 1427 | | |
1438 | 1428 | | |
1439 | 1429 | | |
| |||
1443 | 1433 | | |
1444 | 1434 | | |
1445 | 1435 | | |
1446 | | - | |
| 1436 | + | |
1447 | 1437 | | |
1448 | 1438 | | |
1449 | 1439 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
340 | 341 | | |
341 | 342 | | |
342 | 343 | | |
| |||
359 | 360 | | |
360 | 361 | | |
361 | 362 | | |
| 363 | + | |
| 364 | + | |
362 | 365 | | |
363 | 366 | | |
364 | 367 | | |
| |||
468 | 471 | | |
469 | 472 | | |
470 | 473 | | |
| 474 | + | |
471 | 475 | | |
472 | 476 | | |
473 | 477 | | |
| |||
488 | 492 | | |
489 | 493 | | |
490 | 494 | | |
491 | | - | |
| 495 | + | |
492 | 496 | | |
| 497 | + | |
493 | 498 | | |
494 | 499 | | |
495 | 500 | | |
| |||
707 | 712 | | |
708 | 713 | | |
709 | 714 | | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
710 | 727 | | |
711 | 728 | | |
712 | 729 | | |
| |||
740 | 757 | | |
741 | 758 | | |
742 | 759 | | |
| 760 | + | |
743 | 761 | | |
744 | 762 | | |
745 | 763 | | |
| |||
0 commit comments