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 @@ -814,39 +814,6 @@ def noop(): pass
814814 threading .Thread (target = noop ).start ()
815815 # Thread.join() is not called
816816
817- def test_import_from_another_thread (self ):
818- # bpo-1596321: If the threading module is first import from a thread
819- # different than the main thread, threading._shutdown() must handle
820- # this case without logging an error at Python exit.
821- code = textwrap .dedent ('''
822- import _thread
823- import sys
824-
825- event = _thread.allocate_lock()
826- event.acquire()
827-
828- def import_threading():
829- import threading
830- event.release()
831-
832- if 'threading' in sys.modules:
833- raise Exception('threading is already imported')
834-
835- _thread.start_new_thread(import_threading, ())
836-
837- # wait until the threading module is imported
838- event.acquire()
839- event.release()
840-
841- if 'threading' not in sys.modules:
842- raise Exception('threading is not imported')
843-
844- # don't wait until the thread completes
845- ''' )
846- rc , out , err = assert_python_ok ("-c" , code )
847- self .assertEqual (out , b'' )
848- self .assertEqual (err , b'' )
849-
850817
851818class ThreadJoinOnShutdown (BaseTestCase ):
852819
Original file line number Diff line number Diff line change @@ -1440,29 +1440,20 @@ def _shutdown():
14401440
14411441 global _SHUTTING_DOWN
14421442 _SHUTTING_DOWN = True
1443+ # Main thread
1444+ tlock = _main_thread ._tstate_lock
1445+ # The main thread isn't finished yet, so its thread state lock can't have
1446+ # been released.
1447+ assert tlock is not None
1448+ assert tlock .locked ()
1449+ tlock .release ()
1450+ _main_thread ._stop ()
14431451
14441452 # Call registered threading atexit functions before threads are joined.
14451453 # Order is reversed, similar to atexit.
14461454 for atexit_call in reversed (_threading_atexits ):
14471455 atexit_call ()
14481456
1449- # Main thread
1450- if _main_thread .ident == get_ident ():
1451- tlock = _main_thread ._tstate_lock
1452- # The main thread isn't finished yet, so its thread state lock can't
1453- # have been released.
1454- assert tlock is not None
1455- assert tlock .locked ()
1456- tlock .release ()
1457- _main_thread ._stop ()
1458- else :
1459- # bpo-1596321: _shutdown() must be called in the main thread.
1460- # If the threading module was not imported by the main thread,
1461- # _main_thread is the thread which imported the threading module.
1462- # In this case, ignore _main_thread, similar behavior than for threads
1463- # spawned by C libraries or using _thread.start_new_thread().
1464- pass
1465-
14661457 # Join all non-deamon threads
14671458 while True :
14681459 with _shutdown_locks_lock :
You can’t perform that action at this time.
0 commit comments