@@ -1022,32 +1022,28 @@ def f():
10221022 # The thread was joined properly.
10231023 self .assertEqual (os .read (r , 1 ), b"x" )
10241024
1025- def test_daemon_thread (self ):
1026- r , w = self .pipe ()
1027- code = textwrap .dedent (f"""
1025+ @cpython_only
1026+ def test_daemon_threads_fatal_error (self ):
1027+ subinterp_code = f"""if 1:
1028+ import os
10281029 import threading
1029- import sys
1030-
1031- channel = open({ w } , "w", closefd=False)
1032-
1033- def func():
1034- pass
1030+ import time
10351031
1036- thread = threading.Thread(target=func, daemon=True)
1037- try:
1038- thread.start()
1039- except RuntimeError as exc:
1040- print("ok: %s" % exc, file=channel, flush=True)
1041- else:
1042- thread.join()
1043- print("fail: RuntimeError not raised", file=channel, flush=True)
1044- """ )
1045- ret = test .support .run_in_subinterp (code )
1046- self .assertEqual (ret , 0 )
1032+ def f():
1033+ # Make sure the daemon thread is still running when
1034+ # Py_EndInterpreter is called.
1035+ time.sleep({ test .support .SHORT_TIMEOUT } )
1036+ threading.Thread(target=f, daemon=True).start()
1037+ """
1038+ script = r"""if 1:
1039+ import _testcapi
10471040
1048- msg = os .read (r , 100 ).decode ().rstrip ()
1049- self .assertEqual ("ok: daemon thread are not supported "
1050- "in subinterpreters" , msg )
1041+ _testcapi.run_in_subinterp(%r)
1042+ """ % (subinterp_code ,)
1043+ with test .support .SuppressCrashReport ():
1044+ rc , out , err = assert_python_failure ("-c" , script )
1045+ self .assertIn ("Fatal Python error: Py_EndInterpreter: "
1046+ "not the last thread" , err .decode ())
10511047
10521048
10531049class ThreadingExceptionTests (BaseTestCase ):
0 commit comments