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 @@ -1100,39 +1100,6 @@ def noop(): pass
1100
1100
threading .Thread (target = noop ).start ()
1101
1101
# Thread.join() is not called
1102
1102
1103
- def test_import_from_another_thread (self ):
1104
- # bpo-1596321: If the threading module is first import from a thread
1105
- # different than the main thread, threading._shutdown() must handle
1106
- # this case without logging an error at Python exit.
1107
- code = textwrap .dedent ('''
1108
- import _thread
1109
- import sys
1110
-
1111
- event = _thread.allocate_lock()
1112
- event.acquire()
1113
-
1114
- def import_threading():
1115
- import threading
1116
- event.release()
1117
-
1118
- if 'threading' in sys.modules:
1119
- raise Exception('threading is already imported')
1120
-
1121
- _thread.start_new_thread(import_threading, ())
1122
-
1123
- # wait until the threading module is imported
1124
- event.acquire()
1125
- event.release()
1126
-
1127
- if 'threading' not in sys.modules:
1128
- raise Exception('threading is not imported')
1129
-
1130
- # don't wait until the thread completes
1131
- ''' )
1132
- rc , out , err = assert_python_ok ("-c" , code )
1133
- self .assertEqual (out , b'' )
1134
- self .assertEqual (err , b'' )
1135
-
1136
1103
def test_start_new_thread_at_finalization (self ):
1137
1104
code = """if 1:
1138
1105
import _thread
Original file line number Diff line number Diff line change @@ -1585,29 +1585,20 @@ def _shutdown():
1585
1585
1586
1586
global _SHUTTING_DOWN
1587
1587
_SHUTTING_DOWN = True
1588
+ # Main thread
1589
+ tlock = _main_thread ._tstate_lock
1590
+ # The main thread isn't finished yet, so its thread state lock can't have
1591
+ # been released.
1592
+ assert tlock is not None
1593
+ assert tlock .locked ()
1594
+ tlock .release ()
1595
+ _main_thread ._stop ()
1588
1596
1589
1597
# Call registered threading atexit functions before threads are joined.
1590
1598
# Order is reversed, similar to atexit.
1591
1599
for atexit_call in reversed (_threading_atexits ):
1592
1600
atexit_call ()
1593
1601
1594
- # Main thread
1595
- if _main_thread .ident == get_ident ():
1596
- tlock = _main_thread ._tstate_lock
1597
- # The main thread isn't finished yet, so its thread state lock can't
1598
- # have been released.
1599
- assert tlock is not None
1600
- assert tlock .locked ()
1601
- tlock .release ()
1602
- _main_thread ._stop ()
1603
- else :
1604
- # bpo-1596321: _shutdown() must be called in the main thread.
1605
- # If the threading module was not imported by the main thread,
1606
- # _main_thread is the thread which imported the threading module.
1607
- # In this case, ignore _main_thread, similar behavior than for threads
1608
- # spawned by C libraries or using _thread.start_new_thread().
1609
- pass
1610
-
1611
1602
# Join all non-deamon threads
1612
1603
while True :
1613
1604
with _shutdown_locks_lock :
You can’t perform that action at this time.
0 commit comments