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.5.0.tar.gz
(10.2 kB
view hashes)
Built Distribution
Close
Hashes for loop_rate_limiters-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86d4bbd51ff9bb7754d354a1b8e7e97b109b5ba617cdd644fdf6a2fc0b8a6bb2 |
|
MD5 | 8db8a802bf24fedb4533017c4842847a |
|
BLAKE2b-256 | 78d0f29fa9ae13030c0f50e68082d0a6ef71f21f6184a40a3de1106df4ad3f55 |