8000 Add test.support.import_helper.multi_interp_extensions_check(). · python/cpython@ad3fe36 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad3fe36

Browse files
Add test.support.import_helper.multi_interp_extensions_check().
1 parent a3d3a65 commit ad3fe36

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Lib/test/support/import_helper.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ def frozen_modules(enabled=True):
105105
_imp._override_frozen_modules_for_tests(0)
106106

107107

108+
@contextlib.contextmanager
109+
def multi_interp_extensions_check(enabled=True):
110+
"""Force legacy modules to be allowed in subinterpreters (or not).
111+
112+
("legacy" == single-phase init)
113+
114+
This only applies to modules that haven't been imported yet.
115+
It overrides the PyInterpreterConfig.check_multi_interp_extensions
116+
setting (see support.run_in_subinterp_with_config() and
117+
_xxsubinterpreters.create()).
118+
"""
119+
old = _imp._override_multi_interp_extensions_check(1 if enabled else -1)
120+
try:
121+
yield
122+
finally:
123+
_imp._override_multi_interp_extensions_check(old)
124+
125+
108126
def import_fresh_module(name, fresh=(), blocked=(), *,
109127
deprecated=False,
110128
usefrozen=False,

Python/import.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2388,8 +2388,9 @@ _imp__override_multi_interp_extensions_check_impl(PyObject *module,
23882388
/*[clinic end generated code: output=3ff043af52bbf280 input=e086a2ea181f92ae]*/
23892389
{
23902390
PyInterpreterState *interp = _PyInterpreterState_GET();
2391+
int oldvalue = interp->override_multi_interp_extensions_check;
23912392
interp->override_multi_interp_extensions_check = override;
2392-
Py_RETURN_NONE;
2393+
return PyLong_FromLong(oldvalue);
23932394
}
23942395

23952396
/* Common implementation for _imp.exec_dynamic and _imp.exec_builtin */

0 commit comments

Comments
 (0)
0