Loop rate limiters.
Low maintenance activity. Last release 16 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
$
pip install loop-rate-limitersLoop rate limiters
Simple loop frequency regulators in Python with an API similar to rospy.Rate:
from loop_rate_limiters import RateLimiter
from time import perf_counter
rate = RateLimiter(frequency=400.0)
while True:
print(f"Hello from loop at {perf_counter():.3f} s")
rate.sleep()
A similar AsyncRateLimiter class is available for asynchronous code.
Installation
From conda-forge
conda install -c conda-forge loop-rate-limiters
From PyPI
pip install loop-rate-limiters
Usage
While the example above is synchronous, this library also provides an AsyncRateLimiter class for asyncio:
import asyncio
from loop_rate_limiters import AsyncRateLimiter
async def main():
rate = AsyncRateLimiter(frequency=400.0)
while True:
loop_time = asyncio.get_event_loop().time()
print(f"Hello from loop at {loop_time:.3f} s")
await rate.sleep()
asyncio.run(main())
This can be used when there are several tasks executed in parallel at different frequencies.
See also
- : single-thread interval scheduler in Python