Eric Snow added the comment:

Keep in mind that the global import lock is only held long enough to create a 
module-level lock.  The cache of module locks is found at line 166 of 
Lib/importlib/ and the code related to module-level locking 
follows.  So unfortunately it won't be as simple as just getting the thread 
info from the global import lock.

Regardless, would it be useful to expose a function in importlib.util that 
indicates whether or not the current thread is importing a module (actually the 
names of the modules it is importing)?  Something like that would probably 
check both the global import lock and the module level locks, but make it 
unnecessary to expose the locks directly.  Given the situation with 
module-level locks I image such a helper is going to be desirable.

nosy: +brett.cannon, eric.snow, ncoghlan

Python tracker <>
Python-bugs-list mailing list

Reply via email to