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 to Thread.join. For example, in test_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 calling Thread.is_alive afterwards to differentiate timeouts vs. successful joins, but is_alive() may return False "too soon", while the OS thread is still alive.
(Split off from #136692)
cc @mpage @gpshead
Linked PRs
Feature or enhancement
Currently,
Thread.is_alivewill returnFalseshortly after therun()function finishes, even though the underlying OS thread may still be alive.In #110829, we made
Thread.joincall the OS join API so that it waits for the OS thread to actually exit. We should apply the same behavior toThread.is_alive():Thread.is_aliveas 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.Thread.join(timeout=...)requires callingThread.is_aliveafterwards to differentiate timeouts vs. successful joins, butis_alive()may return False "too soon", while the OS thread is still alive.(Split off from #136692)
cc @mpage @gpshead
Linked PRs
Thread.is_alive()to only return False after the underlying OS thread exits #137315Thread.is_alive()only returns False after the underlying OS thread exits (gh-137315) #138916Thread.is_alive()only returns False after the underlying OS thread exits (gh-137315) #138917