Guava Avatar

Solid Python sketch refactor remix v2 remix

Forked from Solid Python sketch refactor remix v2

View full fork lineage
  1. Solid Python sketch refactor remix v2 · @lychee_bh6e · 2026-04-14 08:35:54
  2. Solid Python sketch refactor remix v2 · @mango_LIOA · 2026-04-14 08:35:54
  3. Solid Python sketch refactor remix · @pomelo_qiiR · 2026-04-14 08:35:54
  4. Solid Python sketch refactor · @rambutan_Pnb5 · 2026-04-14 08:35:54
  5. Solid Python sketch refactor · @kiwi_7OS0 · 2026-04-14 08:35:54
  6. Solid Python sketch · @durian_Vzhs · 2026-04-14 08:35:54

Download

Pulling this python pattern out of a larger project — might be useful on its own.

debounce.py python

A decorator that debounces a function by N seconds.

import threading
import functools

def debounce(wait_seconds: float):
    def decorator(fn):
        timer = None

        @functools.wraps(fn)
        def wrapper(*args, **kwargs):
            nonlocal timer
            if timer is not None:
                timer.cancel()
            timer = threading.Timer(wait_seconds, lambda: fn(*args, **kwargs))
            timer.daemon = True
            timer.start()

        return wrapper
    return decorator

Feel free to fork and adapt.

Developer Discussions