Skip to content

Commit 4b35a8e

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 8df7c87 commit 4b35a8e

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
@@ -1100,39 +1100,6 @@ def noop(): pass
11001100
threading.Thread(target=noop).start()
11011101
# Thread.join() is not called
11021102

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-
11361103
def test_start_new_thread_at_finalization(self):
11371104
code = """if 1:
11381105
import _thread

Lib/threading.py

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

15861586
global _SHUTTING_DOWN
15871587
_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()
15881596

15891597
# Call registered threading atexit functions before threads are joined.
15901598
# Order is reversed, similar to atexit.
15911599
for atexit_call in reversed(_threading_atexits):
15921600
atexit_call()
15931601

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-
16111602
# Join all non-deamon threads
16121603
while True:
16131604
with _shutdown_locks_lock:

0 commit comments

Comments
 (0)