File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1015,39 +1015,6 @@ def noop(): pass
10151015 threading .Thread (target = noop ).start ()
10161016 # Thread.join() is not called
10171017
1018- def test_import_from_another_thread (self ):
1019- # bpo-1596321: If the threading module is first import from a thread
1020- # different than the main thread, threading._shutdown() must handle
1021- # this case without logging an error at Python exit.
1022- code = textwrap .dedent ('''
1023- import _thread
1024- import sys
1025-
1026- event = _thread.allocate_lock()
1027- event.acquire()
1028-
1029- def import_threading():
1030- import threading
1031- event.release()
1032-
1033- if 'threading' in sys.modules:
1034- raise Exception('threading is already imported')
1035-
1036- _thread.start_new_thread(import_threading, ())
1037-
1038- # wait until the threading module is imported
1039- event.acquire()
1040- event.release()
1041-
1042- if 'threading' not in sys.modules:
1043- raise Exception('threading is not imported')
1044-
1045- # don't wait until the thread completes
1046- ''' )
1047- rc , out , err = assert_python_ok ("-c" , code )
1048- self .assertEqual (out , b'' )
1049- self .assertEqual (err , b'' )
1050-
10511018
10521019class ThreadJoinOnShutdown (BaseTestCase ):
10531020
Original file line number Diff line number Diff line change @@ -1565,29 +1565,20 @@ def _shutdown():
15651565
15661566 global _SHUTTING_DOWN
15671567 _SHUTTING_DOWN = True
1568+ # Main thread
1569+ tlock = _main_thread ._tstate_lock
1570+ # The main thread isn't finished yet, so its thread state lock can't have
1571+ # been released.
1572+ assert tlock is not None
1573+ assert tlock .locked ()
1574+ tlock .release ()
1575+ _main_thread ._stop ()
15681576
15691577 # Call registered threading atexit functions before threads are joined.
15701578 # Order is reversed, similar to atexit.
15711579 for atexit_call in reversed (_threading_atexits ):
15721580 atexit_call ()
15731581
1574- # Main thread
1575- if _main_thread .ident == get_ident ():
1576- tlock = _main_thread ._tstate_lock
1577- # The main thread isn't finished yet, so its thread state lock can't
1578- # have been released.
1579- assert tlock is not None
1580- assert tlock .locked ()
1581- tlock .release ()
1582- _main_thread ._stop ()
1583- else :
1584- # bpo-1596321: _shutdown() must be called in the main thread.
1585- # If the threading module was not imported by the main thread,
1586- # _main_thread is the thread which imported the threading module.
1587- # In this case, ignore _main_thread, similar behavior than for threads
1588- # spawned by C libraries or using _thread.start_new_thread().
1589- pass
1590-
15911582 # Join all non-deamon threads
15921583 while True :
15931584 with _shutdown_locks_lock :
You can’t perform that action at this time.
0 commit comments