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 tim.peters
Recipients Tamas.K, csernazs, grahamd, jcea, ncoghlan, neologix, pitrou, python-dev, tim.peters
Date 2013-09-05.03:49:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Fudge - there's another unlikely problem here.  For example:  main program creates a threading.Thread t, runs it, and does t.join(5) (whatever - any timeout value).  When t.join() returns, the main program has no idea whether t is done or not.  Suppose t isn't done, but finishes _bootstrap_inner a microsecond (whatever) later.

Now the user follows the doc's advice, and checks t.is_alive() to see whether it still needs to join t.  t.is_alive() returns False!  _bootstrap_inner() already finished, so the t._stopped event is already set.

So the main program skips doing another t.join(), and lets the program exit.  There's no guarantee then that t's tstate has been cleared, and we can be back to same fatal error that started this.

Of course this has nothing to do with the patch switching from a Condition to an Event to manage the stopped state (good change!) - it has to do with that, no matter how it's coded, _bootstrap_inner() says "this thread is done" before the tstate is unlinked from the chain.

For a related reason, note that Python's threading._shutdown() doesn't prevent the fatal shutdown error even after the patch!  _pickSomeNonDaemonThread() also ignores threads for which is_alive() returns False.  As above, that can return False while the tstate is still in the chain, and then threading._shutdown() never joins such a thread.  join() can't fix the problem if it's not called.  I supposed that one can be repaired by removing the is_alive() check in _pickSomeNonDaemonThread() (i.e., always join() every non-daemon thread).

In their favor, the probabilistic "sleep" approaches would almost always "fix" these too ;-)
Date User Action Args
2013-09-05 03:49:41tim.peterssetrecipients: + tim.peters, jcea, csernazs, ncoghlan, pitrou, grahamd, neologix, python-dev, Tamas.K
2013-09-05 03:49:41tim.peterssetmessageid: <>
2013-09-05 03:49:41tim.peterslinkissue18808 messages
2013-09-05 03:49:39tim.peterscreate