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 @@ -987,39 +987,6 @@ def noop(): pass
987
987
threading .Thread (target = noop ).start ()
988
988
# Thread.join() is not called
989
989
990
- def test_import_from_another_thread (self ):
991
- # bpo-1596321: If the threading module is first import from a thread
992
- # different than the main thread, threading._shutdown() must handle
993
- # this case without logging an error at Python exit.
994
- code = textwrap .dedent ('''
995
- import _thread
996
- import sys
997
-
998
- event = _thread.allocate_lock()
999
- event.acquire()
1000
-
1001
- def import_threading():
1002
- import threading
1003
- event.release()
1004
-
1005
- if 'threading' in sys.modules:
1006
- raise Exception('threading is already imported')
1007
-
1008
- _thread.start_new_thread(import_threading, ())
1009
-
1010
- # wait until the threading module is imported
1011
- event.acquire()
1012
- event.release()
1013
-
1014
- if 'threading' not in sys.modules:
1015
- raise Exception('threading is not imported')
1016
-
1017
- # don't wait until the thread completes
1018
- ''' )
1019
- rc , out , err = assert_python_ok ("-c" , code )
1020
- self .assertEqual (out , b'' )
1021
- self .assertEqual (err , b'' )
1022
-
1023
990
def test_start_new_thread_at_exit (self ):
1024
991
code = """if 1:
1025
992
import atexit
Original file line number Diff line number Diff line change @@ -1565,29 +1565,20 @@ def _shutdown():
1565
1565
1566
1566
global _SHUTTING_DOWN
1567
1567
_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 ()
1568
1576
1569
1577
# Call registered threading atexit functions before threads are joined.
1570
1578
# Order is reversed, similar to atexit.
1571
1579
for atexit_call in reversed (_threading_atexits ):
1572
1580
atexit_call ()
1573
1581
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
-
1591
1582
# Join all non-deamon threads
1592
1583
while True :
1593
1584
with _shutdown_locks_lock :
You can’t perform that action at this time.
0 commit comments