Skip to content

gh-137173: Allow signal handling in isolated subinterpreters #137174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Fix test_capi.
  • Loading branch information
ZeroIntensity committed Jul 28, 2025
commit fc967a26dff6da36232b84790dcdefafd3a5cbe5
1 change: 1 addition & 0 deletions Lib/test/test_capi/test_getargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,7 @@ def test_gh_119213(self):
use_main_obmalloc=False,
gil=2,
check_multi_interp_extensions=True,
can_handle_signals=True,
)
rc = support.run_in_subinterp_with_config(script, **config)
assert rc == 0
Expand Down
47 changes: 29 additions & 18 deletions Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,8 +1730,9 @@ def test_configured_settings(self):
DAEMON_THREADS = 1<<11
FORK = 1<<15
EXEC = 1<<16
SIGNALS = 1<<17
ALL_FLAGS = (OBMALLOC | FORK | EXEC | THREADS | DAEMON_THREADS
| EXTENSIONS);
| EXTENSIONS | SIGNALS);

features = [
'obmalloc',
Expand All @@ -1741,23 +1742,25 @@ def test_configured_settings(self):
'daemon_threads',
'extensions',
'own_gil',
'signals',
]
kwlist = [f'allow_{n}' for n in features]
kwlist[0] = 'use_main_obmalloc'
kwlist[-2] = 'check_multi_interp_extensions'
kwlist[-1] = 'own_gil'
kwlist[-3] = 'check_multi_interp_extensions'
kwlist[-2] = 'own_gil'
kwlist[-1] = 'can_handle_signals'

expected_to_work = {
(True, True, True, True, True, True, True):
(True, True, True, True, True, True, True, True):
(ALL_FLAGS, True),
(True, False, False, False, False, False, False):
(True, False, False, False, False, False, False, False):
(OBMALLOC, False),
(False, False, False, True, False, True, False):
(False, False, False, True, False, True, False, False):
(THREADS | EXTENSIONS, False),
}

expected_to_fail = {
(False, False, False, False, False, False, False),
(False, False, False, False, False, False, False, False),
}

# gh-117649: The free-threaded build does not currently allow
Expand Down Expand Up @@ -1824,14 +1827,16 @@ def test_overridden_setting_extensions_subinterp_check(self):
DAEMON_THREADS = 1<<11
FORK = 1<<15
EXEC = 1<<16
BASE_FLAGS = OBMALLOC | FORK | EXEC | THREADS | DAEMON_THREADS
SIGNALS = 1<<17
BASE_FLAGS = OBMALLOC | FORK | EXEC | THREADS | DAEMON_THREADS | SIGNALS
base_kwargs = {
'use_main_obmalloc': True,
'allow_fork': True,
'allow_exec': True,
'allow_threads': True,
'allow_daemon_threads': True,
'own_gil': False,
'can_handle_signals': True
}

def check(enabled, override):
Expand Down Expand Up @@ -1961,6 +1966,7 @@ class InterpreterConfigTests(unittest.TestCase):
allow_threads=True,
allow_daemon_threads=False,
check_multi_interp_extensions=True,
can_handle_signals=True,
gil='own',
),
'legacy': types.SimpleNamespace(
Expand All @@ -1970,6 +1976,7 @@ class InterpreterConfigTests(unittest.TestCase):
allow_threads=True,
allow_daemon_threads=True,
check_multi_interp_extensions=bool(Py_GIL_DISABLED),
can_handle_signals=False,
gil='shared',
),
'empty': types.SimpleNamespace(
Expand All @@ -1979,6 +1986,7 @@ class InterpreterConfigTests(unittest.TestCase):
allow_threads=False,
allow_daemon_threads=False,
check_multi_interp_extensions=False,
can_handle_signals=False,
gil='default',
),
}
Expand All @@ -1991,16 +1999,18 @@ def iter_all_configs(self):
for allow_threads in (True, False):
for allow_daemon in (True, False):
for checkext in (True, False):
for gil in ('shared', 'own', 'default'):
yield types.SimpleNamespace(
use_main_obmalloc=use_main_obmalloc,
allow_fork=allow_fork,
allow_exec=allow_exec,
allow_threads=allow_threads,
allow_daemon_threads=allow_daemon,
check_multi_interp_extensions=checkext,
gil=gil,
)
for handle_signals in (True, False):
for gil in ('shared', 'own', 'default'):
yield types.SimpleNamespace(
use_main_obmalloc=use_main_obmalloc,
allow_fork=allow_fork,
allow_exec=allow_exec,
allow_threads=allow_threads,
allow_daemon_threads=allow_daemon,
check_multi_interp_extensions=checkext,
can_handle_signals=handle_signals,
gil=gil,
)

def assert_ns_equal(self, ns1, ns2, msg=None):
# This is mostly copied from TestCase.assertDictEqual.
Expand Down Expand Up @@ -2175,6 +2185,7 @@ def new_interp(config):
with self.subTest('main'):
expected = _interpreters.new_config('legacy')
expected.gil = 'own'
expected.can_handle_signals = True
if Py_GIL_DISABLED:
expected.check_multi_interp_extensions = False
interpid, *_ = _interpreters.get_main()
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,7 @@ def func():
allow_threads={allowed},
allow_daemon_threads={daemon_allowed},
check_multi_interp_extensions={check_multi_interp_extensions},
can_handle_signals=True,
own_gil=False,
)
""")
Expand Down