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 int19h
Recipients aldwinaldwin, fabioz, int19h
Date 2019-06-27.10:24:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1561631064.73.0.237158359449.issue37416@roundup.psfhosted.org>
In-reply-to
Content
It's also possible to hit if using some native code that starts a background thread without going via threading, and runs Python code on that background thread. In that case, if that Python code then does "import threading", and threading hasn't been imported yet, then you have this same problem.

Here's a pure Python repro using ctypes on Win32:

#--------------------------
import sys, time
from ctypes import *

ThreadProc = WINFUNCTYPE(c_uint32, c_void_p)

@ThreadProc
def thread_proc(_):
    import threading
    print(threading.current_thread() is threading.main_thread())
    return 0

assert "threading" not in sys.modules
#import threading  # uncomment to fix

windll.kernel32.CreateThread(None, c_size_t(0), thread_proc, None, c_uint32(0), None)
time.sleep(1)

assert "threading" in sys.modules
import threading
print(threading.current_thread() is threading.main_thread())
#--------------------------

Here's the output:

>py -3 main.py
True
False
Exception ignored in: <module 'threading' from 'C:\\Python\\3.7-64\\lib\\threading.py'>
Traceback (most recent call last):
  File "C:\Python\3.7-64\lib\threading.py", line 1276, in _shutdown
    assert tlock.locked()
AssertionError:
History
Date User Action Args
2019-06-27 10:24:24int19hsetrecipients: + int19h, fabioz, aldwinaldwin
2019-06-27 10:24:24int19hsetmessageid: <1561631064.73.0.237158359449.issue37416@roundup.psfhosted.org>
2019-06-27 10:24:24int19hlinkissue37416 messages
2019-06-27 10:24:24int19hcreate