Skip to content

Commit 705b245

Browse files
committed
00371: Revert "bpo-1596321: Fix threading._shutdown() for the main thread (pythonGH-28549) (pythonGH-28589)"
This reverts commit 38c6773. It introduced regression causing FreeIPA's tests to fail. For more info see: https://bodhi.fedoraproject.org/updates/FEDORA-2021-e152ce5f31 GrahamDumpleton/mod_wsgi#730
1 parent f545b96 commit 705b245

File tree

2 files changed

+8
-50
lines changed

2 files changed

+8
-50
lines changed

Lib/test/test_threading.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -987,39 +987,6 @@ def noop(): pass
987987
threading.Thread(target=noop).start()
988988
# Thread.join() is not called
989989

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-
1023990
def test_start_new_thread_at_exit(self):
1024991
code = """if 1:
1025992
import atexit

Lib/threading.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,29 +1565,20 @@ def _shutdown():
15651565

15661566
global _SHUTTING_DOWN
15671567
_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()
15681576

15691577
# Call registered threading atexit functions before threads are joined.
15701578
# Order is reversed, similar to atexit.
15711579
for atexit_call in reversed(_threading_atexits):
15721580
atexit_call()
15731581

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-
15911582
# Join all non-deamon threads
15921583
while True:
15931584
with _shutdown_locks_lock:

0 commit comments

Comments
 (0)