colesbury · GitHub

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

Read the original on github.com ↗