debounce
Debounced function delays invoking the function until after wait seconds have
elapsed since the last time the debounced function was invoked. The debounced
function comes with a cancel method to cancel delayed function invocations
and a flush method to immediately invoke them.
Additional arguments
leading=True- If you want it to call your function immediately on invocation.max_wait=x- The maximum time the decorated function is allowed to be delayed before it's invoked.
Installation
pip install py-debounce
Usage
from debounce import debounce
@debounce(0.1)
def handle_event(e):
"""Computationally heavy methods that potentially gets polled a lot."""
Cancel
from debounce import debounce
@debounce(0.1)
def handle_event(e):
"""Computationally heavy methods that potentially gets polled a lot."""
# Imagine that the event has been called
handle_event(...)
# You can then cancel it by calling. The function will now never be called.
handle_event.cancel()
Flush
from debounce import debounce
@debounce(0.1)
def handle_event(e):
"""Computationally heavy methods that potentially gets polled a lot."""
# Imagine that the event has been called
handle_event(...)
# You can flush the call to immediately call it.
handle_event.flush()
Asyncio
It also handles async functions.
from debounce import debounce
@debounce(0.1)
async def event(e):
"""Computationally heavy methods that potentially gets polled a lot."""
Metadata
Release files for py-debounce 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| py_debounce-0.1.2.tar.gz | 17.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_debounce-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.7 kB
Release files / py_debounce-0.1.2.tar.gz
| Download URL | py_debounce-0.1.2.tar.gz |
|---|---|
| Size | 17.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3253fde4bd00c02a0a9cfed72ba02e4a5a353bdf55544eea226b5532e0af20b8
|
|
BLAKE2b-256 checksum How to use checksums |
d8243d59b20ab8579a9cad675ae36fcae6176448912686e87f3086dd837bae9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.9
|
Release files / py_debounce-0.1.2-py3-none-any.whl
| Download URL | py_debounce-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d4b3a63d6b9c85851166b68d114f90ef0552d894ba805c37e0e733f394ab516
|
|
BLAKE2b-256 checksum How to use checksums |
e5dd53072abbc13429d7b964d59ef0b347a4620de5a2bcefa40b49372e493691
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.9
|