#NEWLINE# def locked( path , timeout = None ) : #NEWLINE# #INDENT# "Decorator which enables locks for decorated function.\n\n    Arguments:\n     - path: path for lockfile.\n     - timeout (optional): Timeout for acquiring lock.\n\n     Usage:\n         @locked('/var/run/myname', timeout=0)\n         def myname(...):\n             ...\n    " #NEWLINE# def decor( func ) : #NEWLINE# #INDENT# @ functools . wraps ( func ) #NEWLINE# def wrapper( * args , **kwargs ) : #NEWLINE# #INDENT# lock = FileLock ( path , timeout = timeout ) #NEWLINE# lock . acquire ( ) #NEWLINE# try : #NEWLINE# #INDENT# return func ( * args , ** kwargs ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# lock . release ( ) #NEWLINE# #UNINDENT# #UNINDENT# return wrapper #NEWLINE# #UNINDENT# return timeout