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 @@ -956,39 +956,6 @@ def test_debug_deprecation(self):
956956 b'is deprecated and will be removed in Python 3.12' )
957957 self .assertIn (msg , err )
958958
959- def test_import_from_another_thread (self ):
960- # bpo-1596321: If the threading module is first import from a thread
961- # different than the main thread, threading._shutdown() must handle
962- # this case without logging an error at Python exit.
963- code = textwrap .dedent ('''
964- import _thread
965- import sys
966-
967- event = _thread.allocate_lock()
968- event.acquire()
969-
970- def import_threading():
971- import threading
972- event.release()
973-
974- if 'threading' in sys.modules:
975- raise Exception('threading is already imported')
976-
977- _thread.start_new_thread(import_threading, ())
978-
979- # wait until the threading module is imported
980- event.acquire()
981- event.release()
982-
983- if 'threading' not in sys.modules:
984- raise Exception('threading is not imported')
985-
986- # don't wait until the thread completes
987- ''' )
988- rc , out , err = assert_python_ok ("-c" , code )
989- self .assertEqual (out , b'' )
990- self .assertEqual (err , b'' )
991-
992959
993960class ThreadJoinOnShutdown (BaseTestCase ):
994961
Original file line number Diff line number Diff line change @@ -1546,29 +1546,20 @@ def _shutdown():
15461546
15471547 global _SHUTTING_DOWN
15481548 _SHUTTING_DOWN = True
1549+ # Main thread
1550+ tlock = _main_thread ._tstate_lock
1551+ # The main thread isn't finished yet, so its thread state lock can't have
1552+ # been released.
1553+ assert tlock is not None
1554+ assert tlock .locked ()
1555+ tlock .release ()
1556+ _main_thread ._stop ()
15491557
15501558 # Call registered threading atexit functions before threads are joined.
15511559 # Order is reversed, similar to atexit.
15521560 for atexit_call in reversed (_threading_atexits ):
15531561 atexit_call ()
15541562
1555- # Main thread
1556- if _main_thread .ident == get_ident ():
1557- tlock = _main_thread ._tstate_lock
1558- # The main thread isn't finished yet, so its thread state lock can't
1559- # have been released.
1560- assert tlock is not None
1561- assert tlock .locked ()
1562- tlock .release ()
1563- _main_thread ._stop ()
1564- else :
1565- # bpo-1596321: _shutdown() must be called in the main thread.
1566- # If the threading module was not imported by the main thread,
1567- # _main_thread is the thread which imported the threading module.
1568- # In this case, ignore _main_thread, similar behavior than for threads
1569- # spawned by C libraries or using _thread.start_new_thread().
1570- pass
1571-
15721563 # Join all non-deamon threads
15731564 while True :
15741565 with _shutdown_locks_lock :
You can’t perform that action at this time.
0 commit comments