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 @@ -965,39 +965,6 @@ def test_debug_deprecation(self):
965
965
b'is deprecated and will be removed in Python 3.12' )
966
966
self .assertIn (msg , err )
967
967
968
- def test_import_from_another_thread (self ):
969
- # bpo-1596321: If the threading module is first import from a thread
970
- # different than the main thread, threading._shutdown() must handle
971
- # this case without logging an error at Python exit.
972
- code = textwrap .dedent ('''
973
- import _thread
974
- import sys
975
-
976
- event = _thread.allocate_lock()
977
- event.acquire()
978
-
979
- def import_threading():
980
- import threading
981
- event.release()
982
-
983
- if 'threading' in sys.modules:
984
- raise Exception('threading is already imported')
985
-
986
- _thread.start_new_thread(import_threading, ())
987
-
988
- # wait until the threading module is imported
989
- event.acquire()
990
- event.release()
991
-
992
- if 'threading' not in sys.modules:
993
- raise Exception('threading is not imported')
994
-
995
- # don't wait until the thread completes
996
- ''' )
997
- rc , out , err = assert_python_ok ("-c" , code )
998
- self .assertEqual (out , b'' )
999
- self .assertEqual (err , b'' )
1000
-
1001
968
1002
969
class ThreadJoinOnShutdown (BaseTestCase ):
1003
970
Original file line number Diff line number Diff line change @@ -1553,29 +1553,20 @@ def _shutdown():
1553
1553
1554
1554
global _SHUTTING_DOWN
1555
1555
_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 ()
1556
1564
1557
1565
# Call registered threading atexit functions before threads are joined.
1558
1566
# Order is reversed, similar to atexit.
1559
1567
for atexit_call in reversed (_threading_atexits ):
1560
1568
atexit_call ()
1561
1569
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
-
1579
1570
# Join all non-deamon threads
1580
1571
while True :
1581
1572
with _shutdown_locks_lock :
You can’t perform that action at this time.
0 commit comments