[Python-Dev] Dealing with import lock deadlock in Import Hooks

Arnaud Fontaine arnaud.fontaine at nexedi.com
Sat Aug 17 10:51:06 CEST 2013


Antoine Pitrou <solipsis at pitrou.net> writes:
> Le Wed, 14 Aug 2013 14:17:59 +0900, Arnaud Fontaine <arnaud.fontaine at nexedi.com> a écrit :
>> From my understanding of import.c source code, until something is
>> added to sys.modules or the code loaded, there should be no
>> side-effect to releasing the lock, right? (eg there is no global
>> variables/data being shared for importing modules, meaning that
>> releasing the lock should be safe as long as the modules loaded
>> through import hooks are protected by a lock)
>
> Er, probably, but import.c is a nasty pile of code.
> It's true the import lock is there mainly to:
> - avoid incomplete modules from being seen by other threads
> - avoid a module from being executed twice

Yes. Hopefully, the implementation in Python 3.3 should be much better! ;-)

> But that doesn't mean it can't have had any other - unintended -
> benefits ;-)

Indeed, that's why I checked the source code, but I will check again
anyway to make sure.

> (also, some import hooks might not be thread-safe, something which they
> haven't had to bother about until now)

Good point, I didn't think about that.

Thanks!

Regards,
-- 
Arnaud Fontaine


More information about the Python-Dev mailing list