(path, timeout=None)
return decor
Decorator which enables locks for decorated function.

    Arguments:
     - path: path for lockfile.
     - timeout (optional): Timeout for acquiring lock.

     Usage:
         @locked('/var/run/myname', timeout=0)
         def myname(...):
             ...
Decorator which enables locks for decorated function.
Decorator which enables locks for decorated function .
def locked(path, timeout=None):
    """Decorator which enables locks for decorated function.

    Arguments:
     - path: path for lockfile.
     - timeout (optional): Timeout for acquiring lock.

     Usage:
         @locked('/var/run/myname', timeout=0)
         def myname(...):
             ...
    """
    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