This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author spiv
Recipients
Date 2007-04-19.08:22:36
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
This script always fails for me, usually on the very first iteration:

----
import threading

while True:
    print '.',
    t = threading.Thread(target=lambda: None)
    t.start()
    t.join()
    alive_threads = threading.enumerate()
    assert len(alive_threads) == 1, alive_threads
----

The docs clearly say this is expected to work: Thread.join is described as "Wait until the thread terminates" and threading.enumerate's description says it will "Return a list of all currently active Thread objects ... It excludes terminated threads".  So by the time t.join() returns, the thread should not be reported by threading.enumerate anymore.

The bug appears to be that while the thread is shutting down, join() may exit too early: it waits for the __stopped flag to be set, but the thread hasn't necessarily been removed from the _active dict by that time, so enumerate will report a "stopped" thread.  (Or if you like the bug is that __stopped is can be set while the thread is still in the _active dict.)

A workaround is to filter the results of threading.enumerate() through [t for t in threading.enumerate() if t.isAlive()].
History
Date User Action Args
2007-08-23 14:53:13adminlinkissue1703448 messages
2007-08-23 14:53:13admincreate