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
You can install the library straight from PyPI:
$ pip install loop-rate-limiters
Or equivalently from Conda:
$ conda install -c conda-forge loop-rate-limiters
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-1.0.0.tar.gz
(12.0 kB
view hashes)
Built Distribution
Close
Hashes for loop_rate_limiters-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bec278411fc4d3f35a94f1342cf211e9ad81d8a3d3b9b08f2eeb5e4fd6e9e9d |
|
MD5 | 60c53c659594c84ad38bdf0581470048 |
|
BLAKE2b-256 | 92ad3cd3e1992e79bbc535dcf8ea5591bed7967d6fe2437fbc737f3f14898b6b |