Commit 469849e
Rémy Voet (ryv)
gh-140746: Fix Thread.start() that can hang indefinitely
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 not be able to
signal that it started to the parent thread, and the parent thread will
wait indefinitely.
To fix this, we reintroduce the old timeout for `Thread.start()`
that was used before commit 9e7f1d2.
When the timeout occurs, we check the `_os_thread_handle` to see if
the thread has somehow died. If it has, we can ensure the thread has
been killed without it having sent the start signal.
We also change `Thread._delete()` to use `pop` instead, because
nothing guarantees that the thread exists in
`_active[get_ident()]` (to avoid KeyError). `_bootstrap_inner` might
crash before `_active[self._ident] = self` executes. We also use
`self._ident` because we know that `set_ident` has already been
executed. Remove the old comment of `_delete` because
`_active_limbo_lock` has became reentrant since
243fd011 parent dbe3950 commit 469849e
2 files changed
+35
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1457 | 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 | + | |
1460 | 1486 | | |
1461 | 1487 | | |
1462 | 1488 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1001 | 1001 | | |
1002 | 1002 | | |
1003 | 1003 | | |
1004 | | - | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
1005 | 1012 | | |
1006 | 1013 | | |
1007 | 1014 | | |
| |||
1081 | 1088 | | |
1082 | 1089 | | |
1083 | 1090 | | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
| 1091 | + | |
1089 | 1092 | | |
1090 | 1093 | | |
1091 | 1094 | | |
| |||
0 commit comments