Skip to content

Instantly share code, notes, and snippets.

View AlexisTM's full-sized avatar
🤠

Alexis Paques AlexisTM

🤠
View GitHub Profile
@AlexisTM
AlexisTM / debounce.py
Last active January 4, 2019 20:56 — forked from esromneb/debounce.py
This is a proper debounce function, the way a electrical engineer would think about it.
import time
""" This is a proper debounce function, the way a electrical engineer would think about it.
This wrapper never calls sleep. It has two counters: one for successful calls, and one for rejected calls.
If the wrapped function throws an exception, the counters and debounce timer are still correct """
class Debounce(object):
def __init__(self, period):