Update PEP 338 to reflect changes to run_module implementation (import lock is now held only when really needed)

This commit is contained in:
Nick Coghlan 2006-03-24 13:08:48 +00:00
parent 7e55edbac0
commit 32f10bcf53
1 changed files with 14 additions and 6 deletions

View File

@ -170,10 +170,9 @@ The delegation has the form::
If the argument ``alter_sys`` is supplied and evaluates to ``True``,
then ``sys.argv[0]`` is updated with the value of ``__file__``
and ``sys.modules[__name__]`` is updated with a temporary module
object for the module being executed. The import lock is used to
prevent other threads from seeing the partially initialised module
object. Both ``sys.argv[0]`` and ``sys.modules[__name__]`` are
restored to their original values before this function returns.
object for the module being executed. Both ``sys.argv[0]`` and
``sys.modules[__name__]`` are restored to their original values
before this function returns.
When invoked as a script, the ``runpy`` module finds and executes the
module supplied as the first argument. It adjusts ``sys.argv`` by
@ -203,8 +202,9 @@ the ``runpy`` module. These are listed below.
This may result in ``sys.argv[0]`` being set to ``None`` if file
name information is not available.
- The import lock is used to avoid potential threading issues that arise
when alter_sys is set to True.
- The import lock is NOT used to avoid potential threading issues that
arise when alter_sys is set to True. Instead, it is recommended that
threaded code simply avoid using this flag.
Alternatives
============
@ -232,6 +232,14 @@ single ``run_module()`` function needed to implement the updates to
the ``-m`` switch. In the interests of simplicity, those extra functions
have been dropped from the proposed API.
After the original implementation in SVN, it became clear that holding
the import lock when executing the initial application script was not
correct (e.g. ``python -m test.regrtest test_threadedimport`` failed).
So the ``run_module`` function only holds the import lock during the
actual search for the module, and releases it before execution, even if
``alter_sys`` is set.
References
==========