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.1.tar.gz
(10.2 kB
view hashes)
Built Distribution
Close
Hashes for loop_rate_limiters-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e20fd2c0c5798bd0140fa644554a02a6f949876105ec48981735e16d74ed6a8 |
|
MD5 | 5227979ac99d75e053911a3fdeebf338 |
|
BLAKE2b-256 | 0bb324e518126c13cadd8c0640cebde517f4a8ee983bd0508ed27ca689d2942b |