def synchronized(lock=None):
 if (lock is None):
  lock = threading.Lock()
 def wrapper(function):
  def new_function(*args, **kwargs):
   lock.acquire()
   try:
    return function(*args, **kwargs)
   finally:
    lock.release()
  return new_function
 return wrapper

def synchronized ( lock = None ) : if ( lock is None ) : lock = threading . Lock ( ) def wrapper ( function ) : def new_function ( * args , ** kwargs ) : lock . acquire ( ) try : return function ( * args , ** kwargs ) finally : lock . release ( ) return new_function return wrapper
this wrapper will serialize access to func to a single thread .