Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 80451:bd853311ffe0
Issue #15894: Document why we don't worry about re-acquiring the
global import lock after forking.
| author | Brett Cannon <brett@python.org> |
|---|---|
| date | Thu, 15 Nov 2012 21:39:36 -0500 |
| parents | ee0c0f1c1eb2 |
| children | 6eefe4d537b3 |
line wrap: on
line diff
--- a/Python/import.c Thu Nov 15 16:16:45 2012 -0500 +++ b/Python/import.c Thu Nov 15 21:39:36 2012 -0500 @@ -202,8 +202,11 @@ 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 {
