def debounce(seconds=1):
 def decorator(func):
  func.timer = None
  @wraps(func)
  def wrapper(*args, **kwargs):
   def call():
    func(*args, **kwargs)
    func.timer = None
   if func.timer:
    func.timer.cancel()
   func.timer = Timer(seconds, call)
   func.timer.start()
  return wrapper
 return decorator

def debounce ( seconds = 1 ) : def decorator ( func ) : func . timer = None @ wraps ( func ) def wrapper ( * args , ** kwargs ) : def call ( ) : func ( * args , ** kwargs ) func . timer = None if func . timer : func . timer . cancel ( ) func . timer = Timer ( seconds , call ) func . timer . start ( ) return wrapper return decorator
prevents the decorated function from being called more than every seconds seconds .