From 5610860840aa71b186fc5639211dd268b817d65f Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Tue, 12 Nov 2024 20:53:58 +0000 Subject: 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(). --- Python/import.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Python/import.c') diff --git a/Python/import.c b/Python/import.c index 29bd8bf68ff..09fe95fa1fb 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 */ -- cgit v1.2.3