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 @@ -1587,29 +1587,20 @@ def _shutdown():
1587
1587
1588
1588
global _SHUTTING_DOWN
1589
1589
_SHUTTING_DOWN = True
1590
+ # Main thread
1591
+ tlock = _main_thread ._tstate_lock
1592
+ # The main thread isn't finished yet, so its thread state lock can't have
1593
+ # been released.
1594
+ assert tlock is not None
1595
+ assert tlock .locked ()
1596
+ tlock .release ()
1597
+ _main_thread ._stop ()
1590
1598
1591
1599
# Call registered threading atexit functions before threads are joined.
1592
1600
# Order is reversed, similar to atexit.
1593
1601
for atexit_call in reversed (_threading_atexits ):
1594
1602
atexit_call ()
1595
1603
1596
- # Main thread
1597
- if _main_thread .ident == get_ident ():
1598
- tlock = _main_thread ._tstate_lock
1599
- # The main thread isn't finished yet, so its thread state lock can't
1600
- # have been released.
1601
- assert tlock is not None
1602
- assert tlock .locked ()
1603
- tlock .release ()
1604
- _main_thread ._stop ()
1605
- else :
1606
- # bpo-1596321: _shutdown() must be called in the main thread.
1607
- # If the threading module was not imported by the main thread,
1608
- # _main_thread is the thread which imported the threading module.
1609
- # In this case, ignore _main_thread, similar behavior than for threads
1610
- # spawned by C libraries or using _thread.start_new_thread().
1611
- pass
1612
-
1613
1604
# Join all non-deamon threads
1614
1605
while True :
1615
1606
with _shutdown_locks_lock :
You can’t perform that action at this time.
0 commit comments