Enabling flexible and idiomatic regular execution of tasks.
Project description
zsv.ticker enables flexible and idiomatic regular execution of tasks:
from zsv.ticker import Ticker ticker = Ticker() ticker.start(5) while ticker.tick(): execute_task()
Ticker aims to be more idiomatic and easy to use than a time calculation and sleep call, and further enables the instantaneous termination of a waiting task:
import signal from time import sleep from zsv.ticker import Ticker ticker = Ticker() ticker.start(5) def abort(signum, frame): ticker.stop() signal.signal(signal.SIGINT, abort) while ticker.tick(): print("tick") sleep(2) print("tock")
The above script wraps a stop call in a signal handler registered to SIGINT: hitting Ctrl+C after the script prints “tick” but before it prints “tock” will yield a final “tock” before it terminates.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
zsv.ticker-1.0.1.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for zsv.ticker-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bbe81a088f129360dc6b4777c8f951a191db0ce6d731db43e2ed413880af8e4 |
|
MD5 | 607ad933c977c58c1afc10203ad3423b |
|
BLAKE2b-256 | 34c6fab5e08564b41bb92a6dd9e48fa5e1fd0c529751707e17a718c7e07d4999 |