@@ -1827,6 +1827,34 @@ def test__all__(self):
18271827 support .check__all__ (self , threading , ('threading' , '_thread' ),
18281828 extra = extra , not_exported = not_exported )
18291829
1830+ @requires_subprocess ()
1831+ def test_gh112826_missing__thread__is_main_interpreter (self ):
1832+ with os_helper .temp_dir () as tempdir :
1833+ modname = '_thread_fake'
1834+ import os .path
1835+ filename = os .path .join (tempdir , modname + '.py' )
1836+ with open (filename , 'w' ) as outfile :
1837+ outfile .write ("""if True:
1838+ import _thread
1839+ globals().update(vars(_thread))
1840+ del _is_main_interpreter
1841+ """ )
1842+
1843+ expected_output = b'success!'
1844+ _ , out , err = assert_python_ok ("-c" , f"""if True:
1845+ import sys
1846+ sys.path.insert(0, { tempdir !r} )
1847+ import { modname }
1848+ sys.modules['_thread'] = { modname }
1849+ del sys.modules[{ modname !r} ]
1850+
1851+ import threading
1852+ print({ expected_output .decode ('utf-8' )!r} , end='')
1853+ """ )
1854+
1855+ self .assertEqual (out , expected_output )
1856+ self .assertEqual (err , b'' )
1857+
18301858
18311859class InterruptMainTests (unittest .TestCase ):
18321860 def check_interrupt_main_with_signal_handler (self , signum ):
0 commit comments