diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-05-17 16:55:59 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-05-17 16:55:59 (GMT) |
commit | ea3eb88bcaef775c8f2bbe310053f9990a8c9ea7 (patch) | |
tree | 9461ae28e833a95a79cc4811df68435bf0e00fc3 /Doc/library/imp.rst | |
parent | 5cec9d2ae57da6fb5c424bb297ddb67902393b2d (diff) | |
download | cpython-ea3eb88bcaef775c8f2bbe310053f9990a8c9ea7.zip cpython-ea3eb88bcaef775c8f2bbe310053f9990a8c9ea7.tar.gz cpython-ea3eb88bcaef775c8f2bbe310053f9990a8c9ea7.tar.bz2 |
Issue #9260: A finer-grained import lock.
Most of the import sequence now uses per-module locks rather than the
global import lock, eliminating well-known issues with threads and imports.
Diffstat (limited to 'Doc/library/imp.rst')
-rw-r--r-- | Doc/library/imp.rst | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/Doc/library/imp.rst b/Doc/library/imp.rst index d54bd9d..885cfeb 100644 --- a/Doc/library/imp.rst +++ b/Doc/library/imp.rst @@ -112,18 +112,29 @@ This module provides an interface to the mechanisms used to implement the Return ``True`` if the import lock is currently held, else ``False``. On platforms without threads, always return ``False``. - On platforms with threads, a thread executing an import holds an internal lock - until the import is complete. This lock blocks other threads from doing an - import until the original import completes, which in turn prevents other threads - from seeing incomplete module objects constructed by the original thread while - in the process of completing its import (and the imports, if any, triggered by - that). + On platforms with threads, a thread executing an import first holds a + global import lock, then sets up a per-module lock for the rest of the + import. This blocks other threads from importing the same module until + the original import completes, preventing other threads from seeing + incomplete module objects constructed by the original thread. An + exception is made for circular imports, which by construction have to + expose an incomplete module object at some point. + + .. note:: + Locking semantics of imports are an implementation detail which may + vary from release to release. However, Python ensures that circular + imports work without any deadlocks. + + .. versionchanged:: 3.3 + In Python 3.3, the locking scheme has changed to per-module locks for + the most part. .. function:: acquire_lock() - Acquire the interpreter's import lock for the current thread. This lock should - be used by import hooks to ensure thread-safety when importing modules. + Acquire the interpreter's global import lock for the current thread. + This lock should be used by import hooks to ensure thread-safety when + importing modules. Once a thread has acquired the import lock, the same thread may acquire it again without blocking; the thread must release it once for each time it has @@ -134,8 +145,8 @@ This module provides an interface to the mechanisms used to implement the .. function:: release_lock() - Release the interpreter's import lock. On platforms without threads, this - function does nothing. + Release the interpreter's global import lock. On platforms without + threads, this function does nothing. .. function:: reload(module) |