]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #15894: Document why we don't worry about re-acquiring the
authorBrett Cannon <brett@python.org>
Fri, 16 Nov 2012 02:39:36 +0000 (21:39 -0500)
committerBrett Cannon <brett@python.org>
Fri, 16 Nov 2012 02:39:36 +0000 (21:39 -0500)
global import lock after forking.

Python/import.c

index 2f71b97bc8b099d56e9ab071da1610d3345355be..6882b570600bddd3e3524789c4700a8d178dd567 100644 (file)
@@ -202,8 +202,11 @@ _PyImport_ReInitLock(void)
     if (import_lock_level > 1) {
         /* Forked as a side effect of import */
         long me = PyThread_get_thread_ident();
-        PyThread_acquire_lock(import_lock, 0);
-        /* XXX: can the previous line fail? */
+        /* 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);
         import_lock_thread = me;
         import_lock_level--;
     } else {