|
22 | 22 | from test import support
|
23 | 23 | from test.support import MISSING_C_DOCSTRINGS
|
24 | 24 | from test.support import import_helper
|
| 25 | +from test.support import script_helper |
25 | 26 | from test.support import threading_helper
|
26 | 27 | from test.support import warnings_helper
|
27 | 28 | from test.support import requires_limited_api
|
@@ -1641,6 +1642,36 @@ def subthread():
|
1641 | 1642 |
|
1642 | 1643 | self.assertEqual(actual, int(interpid))
|
1643 | 1644 |
|
| 1645 | + @threading_helper.requires_working_threading() |
| 1646 | + def test_pending_call_creates_thread(self): |
| 1647 | + source = """ |
| 1648 | + import _testinternalcapi |
| 1649 | + import threading |
| 1650 | + import time |
| 1651 | +
|
| 1652 | +
|
| 1653 | + def output(): |
| 1654 | + print(24) |
| 1655 | + time.sleep(1) |
| 1656 | + print(42) |
| 1657 | +
|
| 1658 | +
|
| 1659 | + def callback(): |
| 1660 | + threading.Thread(target=output).start() |
| 1661 | +
|
| 1662 | +
|
| 1663 | + def create_pending_call(): |
| 1664 | + time.sleep(1) |
| 1665 | + _testinternalcapi.simple_pending_call(callback) |
| 1666 | +
|
| 1667 | +
|
| 1668 | + threading.Thread(target=create_pending_call).start() |
| 1669 | + """ |
| 1670 | + return_code, stdout, stderr = script_helper.assert_python_ok('-c', textwrap.dedent(source)) |
| 1671 | + self.assertEqual(return_code, 0) |
| 1672 | + self.assertEqual(stdout, f"24{os.linesep}42{os.linesep}".encode("utf-8")) |
| 1673 | + self.assertEqual(stderr, b"") |
| 1674 | + |
1644 | 1675 |
|
1645 | 1676 | class SubinterpreterTest(unittest.TestCase):
|
1646 | 1677 |
|
@@ -1949,6 +1980,41 @@ def test_module_state_shared_in_global(self):
|
1949 | 1980 | subinterp_attr_id = os.read(r, 100)
|
1950 | 1981 | self.assertEqual(main_attr_id, subinterp_attr_id)
|
1951 | 1982 |
|
| 1983 | + @threading_helper.requires_working_threading() |
| 1984 | + @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()") |
| 1985 | + @requires_subinterpreters |
| 1986 | + def test_pending_call_creates_thread_subinterpreter(self): |
| 1987 | + interpreters = import_helper.import_module("concurrent.interpreters") |
| 1988 | + r, w = os.pipe() |
| 1989 | + source = f"""if True: |
| 1990 | + import _testinternalcapi |
| 1991 | + import threading |
| 1992 | + import time |
| 1993 | + import os |
| 1994 | +
|
| 1995 | +
|
| 1996 | + def output(): |
| 1997 | + time.sleep(1) |
| 1998 | + os.write({w}, b"x") |
| 1999 | +
|
| 2000 | +
|
| 2001 | + def callback(): |
| 2002 | + threading.Thread(target=output).start() |
| 2003 | +
|
| 2004 | +
|
| 2005 | + def create_pending_call(): |
| 2006 | + time.sleep(1) |
| 2007 | + _testinternalcapi.simple_pending_call(callback) |
| 2008 | +
|
| 2009 | +
|
| 2010 | + threading.Thread(target=create_pending_call).start() |
| 2011 | + """ |
| 2012 | + interp = interpreters.create() |
| 2013 | + interp.exec(source) |
| 2014 | + interp.close() |
| 2015 | + data = os.read(r, 1) |
| 2016 | + self.assertEqual(data, b"x") |
| 2017 | + |
1952 | 2018 |
|
1953 | 2019 | @requires_subinterpreters
|
1954 | 2020 | class InterpreterConfigTests(unittest.TestCase):
|
|
0 commit comments