Loop rate limiters.
Project description
Loop 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
PyPI
$ pip install loop-rate-limiters
Conda
$ conda install loop-rate-limiters -c conda-forge
Asynchronous I/O
The AsyncRateLimiter
class provides a loop frequency limiter 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()
if __name__ == "__main__":
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
loop_rate_limiters-0.6.0.tar.gz
(10.0 kB
view hashes)
Built Distribution
Close
Hashes for loop_rate_limiters-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62056467d237b658a605e8dbcba597c3c3e4d16e3de94cfb4e3e380c38e4e0e0 |
|
MD5 | da400900d2aa6a4eb6ec6732d5a49e28 |
|
BLAKE2b-256 | 7eb519d12a078b3c6eb549ac3c83b57470357c9e6b9eaf785a516928dfdf9889 |