def locked(path, timeout=None):
def decor(func):<EOL><INDENT>@functools.wraps(func)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>lock = FileLock(path, timeout=timeout)<EOL>lock.acquire()<EOL>try:<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT>finally:<EOL><INDENT>lock.release()<EOL><DEDENT><DEDENT>return wrapper<EOL><DEDENT>return decor<EOL>
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(...):
             ...