[Python-checkins] r61029 - python/trunk/Doc/library/thread.rst python/trunk/Doc/library/threading.rst

Nick Coghlan ncoghlan at gmail.com
Sun Feb 24 07:17:57 CET 2008


georg.brandl wrote:
> Author: georg.brandl
> Date: Sun Feb 24 00:25:26 2008
> New Revision: 61029
> 
> Modified:
>    python/trunk/Doc/library/thread.rst
>    python/trunk/Doc/library/threading.rst
> Log:
> Document import ./. threading issues. #1720705.
> 
> 
> Modified: python/trunk/Doc/library/thread.rst
> ==============================================================================
> --- python/trunk/Doc/library/thread.rst	(original)
> +++ python/trunk/Doc/library/thread.rst	Sun Feb 24 00:25:26 2008
> @@ -150,6 +150,11 @@
>    exception will be received by an arbitrary thread.  (When the :mod:`signal`
>    module is available, interrupts always go to the main thread.)
>  
> +* The import machinery is not thread safe.  In general, an import may not
> +  have the side effect of importing a module, and only the main thread
> +  should import modules.  Imports within or caused by a thread other than
> +  the main thread isn't safe.

Absolute rubbish - making importing modules thread safe is what the 
import lock is for (see test_threaded_import). The only thing that isn't 
safe is spawning a thread as a side effect of import and then waiting 
for that thread to do something (since it may be waiting to get the 
import lock, which the running thread currently holds).

If we have C code doing unsafe imports we have to fix the C code, not 
warn everybody off from doing imports outside the main thread. Similarly 
if there are crashers at interpreter shutdown.

Cheers,
Nick.


-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-checkins mailing list