Tim Peters added the comment:

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 ;-)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18808>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to