parameters: (name)
return_statement: return lock
docstring: Get or create the module lock for a given module name.
  
      Acquire/release internally the global import lock to protect
      _module_locks.
docstring_summary: Get or create the module lock for a given module name.
docstring_tokens: Get or create the module lock for a given module name .
function: def _get_module_lock(name):
      """Get or create the module lock for a given module name.
  
      Acquire/release internally the global import lock to protect
      _module_locks."""
  
      _imp.acquire_lock()
      try:
          try:
              lock = _module_locks[name]()
          except KeyError:
              lock = None
  
          if lock is None:
              if _thread is None:
                  lock = _DummyModuleLock(name)
              else:
                  lock = _ModuleLock(name)
  
              def cb(ref, name=name):
                  _imp.acquire_lock()
                  try:
                      # bpo-31070: Check if another thread created a new lock
                      # after the previous lock was destroyed
                      # but before the weakref callback was called.
                      if _module_locks.get(name) is ref:
                          del _module_locks[name]
                  finally:
                      _imp.release_lock()
  
              _module_locks[name] = _weakref.ref(lock, cb)
      finally:
          _imp.release_lock()
  
      return lock
function_tokens: def _get_module_lock ( name ) : _imp . acquire_lock ( ) try : try : lock = _module_locks [ name ] ( ) except KeyError : lock = None if lock is None : if _thread is None : lock = _DummyModuleLock ( name ) else : lock = _ModuleLock ( name ) def cb ( ref , name = name ) : _imp . acquire_lock ( ) try : # bpo-31070: Check if another thread created a new lock # after the previous lock was destroyed # but before the weakref callback was called. if _module_locks . get ( name ) is ref : del _module_locks [ name ] finally : _imp . release_lock ( ) _module_locks [ name ] = _weakref . ref ( lock , cb ) finally : _imp . release_lock ( ) return lock