Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4710cf

Browse files
committed
Issue #15894: Document why we don't worry about re-acquiring the
global import lock after forking.
1 parent 1e1e8aa commit e4710cf

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Python/import.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,11 @@ _PyImport_ReInitLock(void)
202202
if (import_lock_level > 1) {
203203
/* Forked as a side effect of import */
204204
long me = PyThread_get_thread_ident();
205-
PyThread_acquire_lock(import_lock, 0);
206-
/* XXX: can the previous line fail? */
205+
/* The following could fail if the lock is already held, but forking as
206+
a side-effect of an import is a) rare, b) nuts, and c) difficult to
207+
do thanks to the lock only being held when doing individual module
208+
locks per import. */
209+
PyThread_acquire_lock(import_lock, NOWAIT_LOCK);
207210
import_lock_thread = me;
208211
import_lock_level--;
209212
} else {

0 commit comments

Comments
 (0)