Skip to content

Commit a5025c2

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 bd7f4d9 commit a5025c2

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
@@ -1587,29 +1587,20 @@ def _shutdown():
15871587

15881588
global _SHUTTING_DOWN
15891589
_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()
15901598

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

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

0 commit comments

Comments
 (0)