`timed-count` provides a generator function that returns an iterator that delays each iteration by the specified time period. It can be used to execute code at a precise frequency.
Project description
timed-count
timed-count
provides a generator function that returns an iterator that delays each iteration by the specified time period. It can be used to execute code at a precise frequency.
timed-count
is a good replacement for a loop that contains a call to time.sleep
. It is precise, does not dependent on the loop execution time, and won't accumulate temporal drift.
Installation
Install from PyPI via:
pip install timed-count
Usage
Basic usage is as follows:
from timed_count import timed_count
for count in timed_count(0.5):
# Prints at exactly every half a second
print(count)
TimedCount(index=0, count=0.0, time=0.000, lag=0.000)
TimedCount(index=1, count=0.5, time=0.500, lag=0.000)
TimedCount(index=2, count=1.0, time=1.000, lag=0.000)
...
For all usage examples see examples/.
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
timed_count-1.0.0.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for timed_count-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd8e8c07e6bd4447bd9f1e2cfd735e7f3a5c78d199161207373232f8059ae9b4 |
|
MD5 | a911334d3928522d7010e8dd6f86e8c2 |
|
BLAKE2b-256 | d8ea2c6a05880f715f9928f5d1c1a608d1e577c560a8390f409b0a6c9044f9e7 |