def call_after(lag):
  """
  Parametrized decorator for calling a function after a time ``lag`` given
  in milliseconds. This cancels simultaneous calls.
  """
  def decorator(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
      wrapper.timer.cancel() # Debounce
      wrapper.timer = threading.Timer(lag, func, args=args, kwargs=kwargs)
      wrapper.timer.start()
    wrapper.timer = threading.Timer(0, lambda: None) # timer.cancel now exists
    return wrapper
  return decorator
def call_after ( lag ) : def decorator ( func ) : @ wraps ( func ) def wrapper ( * args , ** kwargs ) : wrapper . timer . cancel ( ) wrapper . timer = threading . Timer ( lag , func , args = args , kwargs = kwargs ) wrapper . timer . start ( ) wrapper . timer = threading . Timer ( 0 , lambda : None ) return wrapper return decorator
Parametrized decorator for calling a function after a time ``lag`` given
  in milliseconds. This cancels simultaneous calls.