[issue39042] Use the runtime's main thread ID in the threading module.

Eric Snow report at bugs.python.org
Tue Dec 17 12:09:19 EST 2019


Eric Snow <ericsnowcurrently at gmail.com> added the comment:

Hmm, I wonder if this should be considered a regression in 3.8.  As demonstrated in issue38904, the following code changed behavior as of 3.8, under certain conditions:


import signal
import threading

def int_handler():
   ...

if threading.current_thread() == threading.main_thread():
    signal.signal(signal.SIGINT, int_handler)


Note the specific conditions:

* threading and signal have not been imported yet
* the current thread when the module is *imported* is not the main thread (this only affects folks embedding Python)

Also note that the only other help we offer is a "private" function in the C-API: _PyOS_IsMainThread().  That would have given the correct answer, but we do not expect users to call it, and it doesn't help them from Python code anyway.

Also, the same problem existed pre-3.8 if signal and threading were imported in different threads before the above script ran.

Finally, I'm (mostly) confident that this would be a backward-compatible fix.

What do you think about this being a 3.8 regression, Łukasz?

----------
nosy: +lukasz.langa

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


More information about the Python-bugs-list mailing list