diff -r 5d41ebc79738 Lib/test/test_threading.py --- a/Lib/test/test_threading.py Sun Jul 07 09:49:23 2013 +0200 +++ b/Lib/test/test_threading.py Tue Jul 09 18:12:26 2013 -0400 @@ -443,6 +443,20 @@ self.assertEqual(out, '') self.assertEqual(err, '') + @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") + def test_is_alive_after_fork(self): + # Issue #0: is_alive() could sometimes be True on threads that vanished + # after a fork. + + t = threading.Thread(target=lambda: None) + t.start() + pid = os.fork() + if pid == 0: + os._exit(1 if t.is_alive() else 0) + else: + (_, exit_status) = os.waitpid(pid, 0) + self.assertEqual(0, exit_status) + class ThreadJoinOnShutdown(BaseTestCase): diff -r 5d41ebc79738 Lib/threading.py --- a/Lib/threading.py Sun Jul 07 09:49:23 2013 +0200 +++ b/Lib/threading.py Tue Jul 09 18:12:26 2013 -0400 @@ -790,10 +790,10 @@ def __bootstrap_inner(self): try: self._set_ident() - self.__started.set() with _active_limbo_lock: _active[self.__ident] = self del _limbo[self] + self.__started.set() if __debug__: self._note("%s.__bootstrap(): thread started", self)