Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6c6d3a2f
Commit
6c6d3a2f
authored
May 17, 2012
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move import lock-related functions to a separate doc section.
parent
ea3eb88b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
42 deletions
+43
-42
Doc/library/imp.rst
Doc/library/imp.rst
+43
-42
No files found.
Doc/library/imp.rst
View file @
6c6d3a2f
...
...
@@ -107,48 +107,6 @@ This module provides an interface to the mechanisms used to implement the
in ``sys.modules``.
.. function:: lock_held()
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 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 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
acquired it.
On platforms without threads, this function does nothing.
.. function:: release_lock()
Release the interpreter's global import lock. On platforms without
threads, this function does nothing.
.. function:: reload(module)
Reload a previously imported *module*. The argument must be a module object, so
...
...
@@ -246,6 +204,49 @@ file paths.
magic number, as returned by :func:`get_magic`.
The following functions help interact with the import system's internal
locking mechanism. 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. A global import lock is kept for some critical tasks,
such as initializing the per-module locks.
.. function:: lock_held()
Return ``True`` if the global import lock is currently held, else
``False``. On platforms without threads, always return ``False``.
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.
.. function:: acquire_lock()
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
acquired it.
On platforms without threads, this function does nothing.
.. function:: release_lock()
Release the interpreter's global import lock. On platforms without
threads, this function does nothing.
The following constants with integer values, defined in this module, are used
to indicate the search result of :func:`find_module`.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment