summaryrefslogtreecommitdiffstats
path: root/Doc/library/imp.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/imp.rst')
-rw-r--r--Doc/library/imp.rst128
1 files changed, 94 insertions, 34 deletions
diff --git a/Doc/library/imp.rst b/Doc/library/imp.rst
index 1345b25..5cadda9 100644
--- a/Doc/library/imp.rst
+++ b/Doc/library/imp.rst
@@ -30,6 +30,9 @@ This module provides an interface to the mechanisms used to implement the
:const:`PY_SOURCE`, :const:`PY_COMPILED`, or :const:`C_EXTENSION`, described
below.
+ .. deprecated:: 3.3
+ Use the constants defined on :mod:`importlib.machinery` instead.
+
.. function:: find_module(name[, path])
@@ -69,6 +72,9 @@ This module provides an interface to the mechanisms used to implement the
then use :func:`find_module` with the *path* argument set to ``P.__path__``.
When *P* itself has a dotted name, apply this recipe recursively.
+ .. deprecated:: 3.3
+ Use :func:`importlib.find_loader` instead.
+
.. function:: load_module(name, file, pathname, description)
@@ -90,6 +96,10 @@ This module provides an interface to the mechanisms used to implement the
it was not ``None``, even when an exception is raised. This is best done
using a :keyword:`try` ... :keyword:`finally` statement.
+ .. deprecated:: 3.3
+ Unneeded as loaders should be used to load modules and
+ :func:`find_module` is deprecated.
+
.. function:: new_module(name)
@@ -97,37 +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 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).
-
-
-.. 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.
-
- 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 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
@@ -201,14 +180,19 @@ file paths.
source *path*. For example, if *path* is ``/foo/bar/baz.py`` the return
value would be ``/foo/bar/__pycache__/baz.cpython-32.pyc`` for Python 3.2.
The ``cpython-32`` string comes from the current magic tag (see
- :func:`get_tag`). The returned path will end in ``.pyc`` when
- ``__debug__`` is True or ``.pyo`` for an optimized Python
+ :func:`get_tag`; if :attr:`sys.implementation.cache_tag` is not defined then
+ :exc:`NotImplementedError` will be raised). The returned path will end in
+ ``.pyc`` when ``__debug__`` is True or ``.pyo`` for an optimized Python
(i.e. ``__debug__`` is False). By passing in True or False for
*debug_override* you can override the system's value for ``__debug__`` for
extension selection.
*path* need not exist.
+ .. versionchanged:: 3.3
+ If :attr:`sys.implementation.cache_tag` is ``None``, then
+ :exc:`NotImplementedError` is raised.
+
.. function:: source_from_cache(path)
@@ -216,7 +200,13 @@ file paths.
file path. For example, if *path* is
``/foo/bar/__pycache__/baz.cpython-32.pyc`` the returned path would be
``/foo/bar/baz.py``. *path* need not exist, however if it does not conform
- to :pep:`3147` format, a ``ValueError`` is raised.
+ to :pep:`3147` format, a ``ValueError`` is raised. If
+ :attr:`sys.implementation.cache_tag` is not defined,
+ :exc:`NotImplementedError` is raised.
+
+ .. versionchanged:: 3.3
+ Raise :exc:`NotImplementedError` when
+ :attr:`sys.implementation.cache_tag` is not defined.
.. function:: get_tag()
@@ -224,6 +214,64 @@ file paths.
Return the :pep:`3147` magic tag string matching this version of Python's
magic number, as returned by :func:`get_magic`.
+ .. note::
+ You may use :attr:`sys.implementation.cache_tag` directly starting
+ in Python 3.3.
+
+
+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.
+
+
+.. 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.
+
+.. versionchanged:: 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:: 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.
+
+.. versionchanged:: 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:: release_lock()
+
+ Release the interpreter's global import lock. On platforms without
+ threads, this function does nothing.
+
+.. versionchanged:: 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.
+
The following constants with integer values, defined in this module, are used
to indicate the search result of :func:`find_module`.
@@ -233,31 +281,43 @@ to indicate the search result of :func:`find_module`.
The module was found as a source file.
+ .. deprecated:: 3.3
+
.. data:: PY_COMPILED
The module was found as a compiled code object file.
+ .. deprecated:: 3.3
+
.. data:: C_EXTENSION
The module was found as dynamically loadable shared library.
+ .. deprecated:: 3.3
+
.. data:: PKG_DIRECTORY
The module was found as a package directory.
+ .. deprecated:: 3.3
+
.. data:: C_BUILTIN
The module was found as a built-in module.
+ .. deprecated:: 3.3
+
.. data:: PY_FROZEN
The module was found as a frozen module.
+ .. deprecated:: 3.3
+
.. class:: NullImporter(path_string)