File tree 2 files changed +8
-50
lines changed
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):
956
956
b'is deprecated and will be removed in Python 3.12' )
957
957
self .assertIn (msg , err )
958
958
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
-
992
959
993
960
class ThreadJoinOnShutdown (BaseTestCase ):
994
961
Original file line number Diff line number Diff line change @@ -1546,29 +1546,20 @@ def _shutdown():
1546
1546
1547
1547
global _SHUTTING_DOWN
1548
1548
_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 ()
1549
1557
1550
1558
# Call registered threading atexit functions before threads are joined.
1551
1559
# Order is reversed, similar to atexit.
1552
1560
for atexit_call in reversed (_threading_atexits ):
1553
1561
atexit_call ()
1554
1562
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
-
1572
1563
# Join all non-deamon threads
1573
1564
while True :
1574
1565
with _shutdown_locks_lock :
You can’t perform that action at this time.
0 commit comments