Index: Lib/threading.py =================================================================== --- Lib/threading.py (revision 65077) +++ Lib/threading.py (working copy) @@ -814,7 +814,11 @@ # and make it available for the interpreter # (Py_Main) as threading._shutdown. -_shutdown = _MainThread()._exitfunc +_shutdown = None +def __init_threading(): + global _shutdown + _shutdown = _MainThread()._exitfunc +__init_threading() # get thread-local implementation, either from the thread # module, or from the python fallback @@ -839,11 +843,8 @@ new_active = {} current = current_thread() with _active_limbo_lock: - for ident, thread in _active.iteritems(): - if thread is current: - # There is only one active thread. - new_active[ident] = thread - else: + for thread in _active.itervalues(): + if thread is not current: # All the others are already stopped. # We don't call _Thread__stop() because it tries to acquire # thread._Thread__block which could also have been held while @@ -852,10 +853,10 @@ _limbo.clear() _active.clear() - _active.update(new_active) - assert len(_active) == 1 + __init_threading() + # Self-test code def _test():