def synchronized(fn):
    '''
    A decorator which acquires a lock before attempting to execute its wrapped
    function. Releases the lock in a finally clause.

    :param fn: The function to wrap.
    '''
    lock = threading.Lock()

    @functools.wraps(fn)
    def decorated(*args, **kwargs):
        lock.acquire()
        try:
            return fn(*args, **kwargs)
        finally:
            lock.release()

    return decorated
def synchronized ( fn ) : lock = threading . Lock ( ) @ functools . wraps ( fn ) def decorated ( * args , ** kwargs ) : lock . acquire ( ) try : return fn ( * args , ** kwargs ) finally : lock . release ( ) return decorated
A decorator which acquires a lock before attempting to execute its wrapped
    function. Releases the lock in a finally clause.

    :param fn: The function to wrap.