File tree Expand file tree Collapse file tree 2 files changed +8
-50
lines changed Expand file tree Collapse file tree 2 files changed +8
-50
lines changed Original file line number Diff line number Diff line change @@ -1045,39 +1045,6 @@ def test_debug_deprecation(self):
10451045 b'is deprecated and will be removed in Python 3.12' )
10461046 self .assertIn (msg , err )
10471047
1048- def test_import_from_another_thread (self ):
1049- # bpo-1596321: If the threading module is first import from a thread
1050- # different than the main thread, threading._shutdown() must handle
1051- # this case without logging an error at Python exit.
1052- code = textwrap .dedent ('''
1053- import _thread
1054- import sys
1055-
1056- event = _thread.allocate_lock()
1057- event.acquire()
1058-
1059- def import_threading():
1060- import threading
1061- event.release()
1062-
1063- if 'threading' in sys.modules:
1064- raise Exception('threading is already imported')
1065-
1066- _thread.start_new_thread(import_threading, ())
1067-
1068- # wait until the threading module is imported
1069- event.acquire()
1070- event.release()
1071-
1072- if 'threading' not in sys.modules:
1073- raise Exception('threading is not imported')
1074-
1075- # don't wait until the thread completes
1076- ''' )
1077- rc , out , err = assert_python_ok ("-c" , code )
1078- self .assertEqual (out , b'' )
1079- self .assertEqual (err , b'' )
1080-
10811048
10821049class ThreadJoinOnShutdown (BaseTestCase ):
10831050
Original file line number Diff line number Diff line change @@ -1553,29 +1553,20 @@ def _shutdown():
15531553
15541554 global _SHUTTING_DOWN
15551555 _SHUTTING_DOWN = True
1556+ # Main thread
1557+ tlock = _main_thread ._tstate_lock
1558+ # The main thread isn't finished yet, so its thread state lock can't have
1559+ # been released.
1560+ assert tlock is not None
1561+ assert tlock .locked ()
1562+ tlock .release ()
1563+ _main_thread ._stop ()
15561564
15571565 # Call registered threading atexit functions before threads are joined.
15581566 # Order is reversed, similar to atexit.
15591567 for atexit_call in reversed (_threading_atexits ):
15601568 atexit_call ()
15611569
1562- # Main thread
1563- if _main_thread .ident == get_ident ():
1564- tlock = _main_thread ._tstate_lock
1565- # The main thread isn't finished yet, so its thread state lock can't
1566- # have been released.
1567- assert tlock is not None
1568- assert tlock .locked ()
1569- tlock .release ()
1570- _main_thread ._stop ()
1571- else :
1572- # bpo-1596321: _shutdown() must be called in the main thread.
1573- # If the threading module was not imported by the main thread,
1574- # _main_thread is the thread which imported the threading module.
1575- # In this case, ignore _main_thread, similar behavior than for threads
1576- # spawned by C libraries or using _thread.start_new_thread().
1577- pass
1578-
15791570 # Join all non-deamon threads
15801571 while True :
15811572 with _shutdown_locks_lock :
You can’t perform that action at this time.
0 commit comments