mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
bpo-40234: Revert "bpo-37266: Daemon threads are now denied in subinterpreters (GH-14049)" (GH-19456)
This reverts commit 066e5b1a91.
This commit is contained in:
parent
909b87d2bb
commit
14d5331eb5
7 changed files with 21 additions and 91 deletions
|
|
@ -1022,32 +1022,28 @@ def f():
|
|||
# The thread was joined properly.
|
||||
self.assertEqual(os.read(r, 1), b"x")
|
||||
|
||||
def test_daemon_thread(self):
|
||||
r, w = self.pipe()
|
||||
code = textwrap.dedent(f"""
|
||||
@cpython_only
|
||||
def test_daemon_threads_fatal_error(self):
|
||||
subinterp_code = f"""if 1:
|
||||
import os
|
||||
import threading
|
||||
import sys
|
||||
import time
|
||||
|
||||
channel = open({w}, "w", closefd=False)
|
||||
def f():
|
||||
# Make sure the daemon thread is still running when
|
||||
# Py_EndInterpreter is called.
|
||||
time.sleep({test.support.SHORT_TIMEOUT})
|
||||
threading.Thread(target=f, daemon=True).start()
|
||||
"""
|
||||
script = r"""if 1:
|
||||
import _testcapi
|
||||
|
||||
def func():
|
||||
pass
|
||||
|
||||
thread = threading.Thread(target=func, daemon=True)
|
||||
try:
|
||||
thread.start()
|
||||
except RuntimeError as exc:
|
||||
print("ok: %s" % exc, file=channel, flush=True)
|
||||
else:
|
||||
thread.join()
|
||||
print("fail: RuntimeError not raised", file=channel, flush=True)
|
||||
""")
|
||||
ret = test.support.run_in_subinterp(code)
|
||||
self.assertEqual(ret, 0)
|
||||
|
||||
msg = os.read(r, 100).decode().rstrip()
|
||||
self.assertEqual("ok: daemon thread are not supported "
|
||||
"in subinterpreters", msg)
|
||||
_testcapi.run_in_subinterp(%r)
|
||||
""" % (subinterp_code,)
|
||||
with test.support.SuppressCrashReport():
|
||||
rc, out, err = assert_python_failure("-c", script)
|
||||
self.assertIn("Fatal Python error: Py_EndInterpreter: "
|
||||
"not the last thread", err.decode())
|
||||
|
||||
|
||||
class ThreadingExceptionTests(BaseTestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue