-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed
Closed
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Currently, Thread.is_alive
will return False
shortly after the run()
function finishes, even though the underlying OS thread may still be alive.
In #110829, we made Thread.join
call the OS join API so that it waits for the OS thread to actually exit. We should apply the same behavior to Thread.is_alive()
:
- In some places, we use
Thread.is_alive
as an alternative toThread.join
. For example, intest_free_threading.test_monitoring
, the test exits once all the background threads are no longer "alive", but that may be a little too soon -- the OS threads may still be running, which can lead to false positives in the refleak tests. - The pattern for
Thread.join(timeout=...)
requires callingThread.is_alive
afterwards to differentiate timeouts vs. successful joins, butis_alive()
may return False "too soon", while the OS thread is still alive.
(Split off from #136692)
Linked PRs
- gh-137017: Fix
Thread.is_alive()
to only return False after the underlying OS thread exits #137315 - [3.14] gh-137017: Ensure
Thread.is_alive()
only returns False after the underlying OS thread exits (gh-137315) #138916 - [3.13] gh-137017: Ensure
Thread.is_alive()
only returns False after the underlying OS thread exits (gh-137315) #138917
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement