def locked(path, timeout=None):
 def decor(func):
  @functools.wraps(func)
  def wrapper(*args, **kwargs):
   lock = FileLock(path, timeout=timeout)
   lock.acquire()
   try:
    return func(*args, **kwargs)
   finally:
    lock.release()
  return wrapper
 return decor

def locked ( path , timeout = None ) : def decor ( func ) : @ functools . wraps ( func ) def wrapper ( * args , ** kwargs ) : lock = FileLock ( path , timeout = timeout ) lock . acquire ( ) try : return func ( * args , ** kwargs ) finally : lock . release ( ) return wrapper return decor
a context manager for locking an instance of a qmutex .