def atomize(f, lock=None):
lock = lock or threading.RLock()<EOL>@functools.wraps(f)<EOL>def exec_atomic(*args, **kwargs):<EOL><INDENT>lock.acquire()<EOL>try:<EOL><INDENT>return f(*args, **kwargs)<EOL><DEDENT>finally:<EOL><INDENT>lock.release()<EOL><DEDENT><DEDENT>return exec_atomic<EOL>
Decorate a function with a reentrant lock to prevent multiple
threads from calling said thread simultaneously.