MCPcopy Index your code
hub / github.com/python/cpython / _get_module_lock

Function _get_module_lock

Lib/importlib/_bootstrap.py:429–463  ·  view source on GitHub ↗

Get or create the module lock for a given module name. Acquire/release internally the global import lock to protect _module_locks.

(name)

Source from the content-addressed store, hash-verified

427# The following two functions are for consumption by Python/import.c.
428
429def _get_module_lock(name):
430 """Get or create the module lock for a given module name.
431
432 Acquire/release internally the global import lock to protect
433 _module_locks."""
434
435 _imp.acquire_lock()
436 try:
437 try:
438 lock = _module_locks[name]()
439 except KeyError:
440 lock = None
441
442 if lock is None:
443 if _thread is None:
444 lock = _DummyModuleLock(name)
445 else:
446 lock = _ModuleLock(name)
447
448 def cb(ref, name=name):
449 _imp.acquire_lock()
450 try:
451 # bpo-31070: Check if another thread created a new lock
452 # after the previous lock was destroyed
453 # but before the weakref callback was called.
454 if _module_locks.get(name) is ref:
455 del _module_locks[name]
456 finally:
457 _imp.release_lock()
458
459 _module_locks[name] = _weakref.ref(lock, cb)
460 finally:
461 _imp.release_lock()
462
463 return lock
464
465
466def _lock_unlock_module(name):

Callers 2

__enter__Method · 0.85
_lock_unlock_moduleFunction · 0.85

Calls 3

_DummyModuleLockClass · 0.85
_ModuleLockClass · 0.85
acquire_lockMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…