Commit f34cae7
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 this, we reintroduce the timeout for `Thread.start()` that was
removed by commit 9e7f1d2. When the
timeout occurs, we check `_os_thread_handle` to see if the thread has
somehow died. If it has, we can confirm the thread exited without
sending the start signal.
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 df19261 commit f34cae7
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