def mutex(func):
def wrapper(*args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>lock = args[<NUM_LIT:0>].lock<EOL>lock.acquire(True)<EOL>try:<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT>except:<EOL><INDENT>raise<EOL><DEDENT>finally:<EOL><INDENT>lock.release()<EOL><DEDENT><DEDENT>return wrapper<EOL>
use a thread lock on current method, if self.lock is defined