diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-03-09 16:46:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-09 16:46:21 (GMT) |
commit | cf6e7c5e551b3513817d6a77ba88253dc8473298 (patch) | |
tree | ca5e5125a1478a2cbc4c65e4467f8fcf7568f34f /Modules | |
parent | b45d14b88611fefc6f054226d3e1117082d322c8 (diff) | |
download | cpython-cf6e7c5e551b3513817d6a77ba88253dc8473298.zip cpython-cf6e7c5e551b3513817d6a77ba88253dc8473298.tar.gz cpython-cf6e7c5e551b3513817d6a77ba88253dc8473298.tar.bz2 |
gh-100227: Isolate the Import State to Each Interpreter (gh-101941)
Specific changes:
* move the import lock to PyInterpreterState
* move the "find_and_load" diagnostic state to PyInterpreterState
Note that the import lock exists to keep multiple imports of the same module in the same interpreter (but in different threads) from stomping on each other. Independently, we use a distinct global lock to protect globally shared import state, especially related to loaded extension modules. For now we can rely on the GIL as that lock but with a per-interpreter GIL we'll need a new global lock.
The remaining state in _PyRuntimeState.imports will (probably) continue being global.
https://github.com/python/cpython/issues/100227
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/posixmodule.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 7beb2ce..a3d86cb 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -567,18 +567,21 @@ run_at_forkers(PyObject *lst, int reverse) void PyOS_BeforeFork(void) { - run_at_forkers(_PyInterpreterState_GET()->before_forkers, 1); + PyInterpreterState *interp = _PyInterpreterState_GET(); + run_at_forkers(interp->before_forkers, 1); - _PyImport_AcquireLock(); + _PyImport_AcquireLock(interp); } void PyOS_AfterFork_Parent(void) { - if (_PyImport_ReleaseLock() <= 0) + PyInterpreterState *interp = _PyInterpreterState_GET(); + if (_PyImport_ReleaseLock(interp) <= 0) { Py_FatalError("failed releasing import lock after fork"); + } - run_at_forkers(_PyInterpreterState_GET()->after_forkers_parent, 0); + run_at_forkers(interp->after_forkers_parent, 0); } void @@ -604,7 +607,7 @@ PyOS_AfterFork_Child(void) goto fatal_error; } - status = _PyImport_ReInitLock(); + status = _PyImport_ReInitLock(tstate->interp); if (_PyStatus_EXCEPTION(status)) { goto fatal_error; } |