def locked_function(origfunc):
 def wrapped(*args, **kwargs):
  cache_lock.acquire()
  try:
   return origfunc(*args, **kwargs)
  finally:
   cache_lock.release()
 return wrapped

def locked_function ( origfunc ) : def wrapped ( * args , ** kwargs ) : cache_lock . acquire ( ) try : return origfunc ( * args , ** kwargs ) finally : cache_lock . release ( ) return wrapped
decorator to execute function under lock .