[issue9260] A finer grained import lock

Brett Cannon report at bugs.python.org
Wed Jul 14 21:59:37 CEST 2010


Brett Cannon <brett at python.org> added the comment:

On Wed, Jul 14, 2010 at 12:34, Antoine Pitrou <report at bugs.python.org>wrote:

>
> Antoine Pitrou <pitrou at free.fr> added the comment:
>
> > So I say we don't worry about loaders being thread-safe. If __import__
> > handles the locking for a specific module then it will hold the lock
> > on behalf of the loader.
>
> Yes but what happens if two different modules are imported from two
> different threads, and handled by the same loader? The loader could have
> global structures which rely on serialization of imports for
> consistency.
>

That's why I said we should supply a context decorator (or function) which
will handle the lock appropriately, taking the name of the module to import
as an argument so the locking is fine-grained.

----------
Added file: http://bugs.python.org/file18005/unnamed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9260>
_______________________________________
-------------- next part --------------
<br><br><div class="gmail_quote">On Wed, Jul 14, 2010 at 12:34, Antoine Pitrou <span dir="ltr">&lt;<a href="mailto:report at bugs.python.org">report at bugs.python.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br>
Antoine Pitrou &lt;<a href="mailto:pitrou at free.fr">pitrou at free.fr</a>&gt; added the comment:<br>
<div class="im"><br>
&gt; So I say we don&#39;t worry about loaders being thread-safe. If __import__<br>
&gt; handles the locking for a specific module then it will hold the lock<br>
&gt; on behalf of the loader.<br>
<br>
</div>Yes but what happens if two different modules are imported from two<br>
different threads, and handled by the same loader? The loader could have<br>
global structures which rely on serialization of imports for<br>
consistency.<br></blockquote><div><br></div><div>That&#39;s why I said we should supply a context decorator (or function) which will handle the lock appropriately, taking the name of the module to import as an argument so the locking is fine-grained.</div>

</div>


More information about the Python-bugs-list mailing list