From acd9aba2d20fddd3bb2d2a0351d43d4001d4dc8f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 2 Jun 2020 15:12:07 +0200 Subject: [PATCH] bpo-40232: _PyImport_ReInitLock() can now safely use its lock Since _PyImport_ReInitLock() now calls _PyThread_at_fork_reinit() on the import lock, the lock is now in a known state: unlocked. It became safe to acquire it after fork. --- Python/import.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Python/import.c b/Python/import.c index 35724fef37a6bf..505688400ef3e3 100644 --- a/Python/import.c +++ b/Python/import.c @@ -213,11 +213,7 @@ _PyImport_ReInitLock(void) if (import_lock_level > 1) { /* Forked as a side effect of import */ unsigned long me = PyThread_get_thread_ident(); - /* The following could fail if the lock is already held, but forking as - a side-effect of an import is a) rare, b) nuts, and c) difficult to - do thanks to the lock only being held when doing individual module - locks per import. */ - PyThread_acquire_lock(import_lock, NOWAIT_LOCK); + PyThread_acquire_lock(import_lock, WAIT_LOCK); import_lock_thread = me; import_lock_level--; } else {