Issue 30893: Expose importlib._bootstrap._ModuleLockManager in importlib.machinery (original) (raw)
Based on https://github.com/python/cpython/pull/2646/files#r126574323, I'm actually thinking along different lines: I'm starting to think we should move the current sys.modules to sys._modules, and make sys.modules a synchronised wrapper that does the following for all get/set/delete operations:
Acquires the global import lock
Acquires the relevant module lock
Releases the global import lock
Mutates sys._modules
Releases the module lock
That said, I'm not sure that would be sufficient to give the desired level of atomicity, so exposing ModuleLockManager may actually be a better approach.