def once(func):
 lock = threading.Lock()
 def new_func(*args, **kwargs):
  if new_func.called:
   return
  with lock:
   if new_func.called:
    return
   rv = func(*args, **kwargs)
   new_func.called = True
   return rv
 new_func = update_wrapper(new_func, func)
 new_func.called = False
 return new_func

def once ( func ) : lock = threading . Lock ( ) def new_func ( * args , ** kwargs ) : if new_func . called : return with lock : if new_func . called : return rv = func ( * args , ** kwargs ) new_func . called = True return rv new_func = update_wrapper ( new_func , func ) new_func . called = False return new_func
runs a thing once and once only .