timed-count provides an iterator that delays each iteration by a specified time period. It can be used to repeatedly execute code at a precise frequency.
Project description
timed-count
timed-count provides an iterator that delays each iteration by a specified time period. It can be used to repeatedly 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, missed=False)
TimedCount(index=1, count=0.5, time=0.500, missed=False)
TimedCount(index=2, count=1.0, time=1.000, missed=False)
...
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.1.1.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for timed_count-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95a7e50760bf3e1a4932d7c43fa36ad71e449ed3425735d9b3cde753e5ecaeec |
|
MD5 | faa7b1a188e57fcd15e6951d8d0cf002 |
|
BLAKE2b-256 | a8aa6121e39265d434bb63343d6138025542ec0815855f5bb8688909df06e767 |