In Python2, does it need to wrap imp.find/load_module with imp_acquire/release_lock?

Xiang Zhang zhangyangyu0614 at gmail.com
Thu Mar 1 05:41:14 EST 2018


On Wednesday, February 28, 2018 at 3:02:38 PM UTC+8, dieter wrote:
> Xiang Zhang <zhangyangyu0614 at gmail.com> writes:
> 
> > Just like the title. It seems to me it is needed from the source code but codes in stdlib all doesn't do that.
> 
> The "import" machinery uses locks of its own (to protect "sys.modules").
> 
> I assume that "load_module" will use those locks internally.
> "find" might be considered to usually see quite a static situation;
> should your file system be modified by concurrent threads, it might
> be necessary that you use your own locks to protect against this.

I know. But my confusion is that I can't confirm your assumption. I can't find where
the import lock is acquired in its code path.




More information about the Python-list mailing list