summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-11-12 20:53:58 (GMT)
committerGitHub <noreply@github.com>2024-11-12 20:53:58 (GMT)
commit5610860840aa71b186fc5639211dd268b817d65f (patch)
treef6a3b5ad6413f6e0091222ad2bcdf07252b4ed54 /Python/import.c
parentbf224bd7cef5d24eaff35945ebe7ffe14df7710f (diff)
downloadcpython-5610860840aa71b186fc5639211dd268b817d65f.zip
cpython-5610860840aa71b186fc5639211dd268b817d65f.tar.gz
cpython-5610860840aa71b186fc5639211dd268b817d65f.tar.bz2
gh-126688: Reinit import lock after fork (#126692)
The PyMutex implementation supports unlocking after fork because we clear the list of waiters in parking_lot.c. This doesn't work as well for _PyRecursiveMutex because on some systems, such as SerenityOS, the thread id is not preserved across fork().
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Python/import.c b/Python/import.c
index 29bd8bf..09fe95f 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -122,6 +122,13 @@ _PyImport_ReleaseLock(PyInterpreterState *interp)
_PyRecursiveMutex_Unlock(&IMPORT_LOCK(interp));
}
+void
+_PyImport_ReInitLock(PyInterpreterState *interp)
+{
+ // gh-126688: Thread id may change after fork() on some operating systems.
+ IMPORT_LOCK(interp).thread = PyThread_get_thread_ident_ex();
+}
+
/***************/
/* sys.modules */