[issue46726] Thread spuriously marked dead after interrupting a join call

Tim Peters report at bugs.python.org
Sun Feb 13 13:41:15 EST 2022


Tim Peters <tim at python.org> added the comment:

>> is there a bulletproof way to guarantee that `self._stop()` gets 
>> called if the acquire_and_release() succeeds? 

> I don't think it's critical.

Agreed! Anything at the Python level that cares whether the thread is still alive will call _wait_for_tstate_lock() again, and get another chance each time to notice that the tstate lock has been freed.

Instead of:

        try:
            if lock.acquire_and_release(block, timeout):
                self._stop
        except:
            if not lock.locked():
                self._stop()

I'd prefer:

        try:
            lock.acquire_and_release(block, timeout)
        finally:
            if not lock.locked():
                self._stop()

Because, at the Python level, whether acquire_and_release() succeeded at its task depends entirely on whether the lock is free afterward. That's what we're _really_ looking for, and is so on all possible platforms.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46726>
_______________________________________


More information about the Python-bugs-list mailing list