summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-04-12 21:45:09 (GMT)
committerGitHub <noreply@github.com>2020-04-12 21:45:09 (GMT)
commit14d5331eb5e6c38be12bad421bd59ad0fac9e448 (patch)
tree4f9c3351cc8f6cb2fa397b56a4a6c37c547cef87 /Lib/test/test_threading.py
parent909b87d2bb3d6330d39c48e43f7f50f4d086cc41 (diff)
downloadcpython-14d5331eb5e6c38be12bad421bd59ad0fac9e448.zip
cpython-14d5331eb5e6c38be12bad421bd59ad0fac9e448.tar.gz
cpython-14d5331eb5e6c38be12bad421bd59ad0fac9e448.tar.bz2
bpo-40234: Revert "bpo-37266: Daemon threads are now denied in subinterpreters (GH-14049)" (GH-19456)
This reverts commit 066e5b1a917ec2134e8997d2cadd815724314252.
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py42
1 files changed, 19 insertions, 23 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 8a4efd6..81e5f70 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -1022,32 +1022,28 @@ class SubinterpThreadingTests(BaseTestCase):
# 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
-
- channel = open({w}, "w", closefd=False)
-
- def func():
- pass
+ import time
- 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)
+ 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
- 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):