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
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
- ischedule: single-thread interval scheduler in Python
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file loop_rate_limiters-1.2.0.tar.gz.
File metadata
- Download URL: loop_rate_limiters-1.2.0.tar.gz
- Upload date:
- Size: 35.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7187ec1f76f282ee7166d85c8e29eb13dd850422577decaf7e6bfc803173b421
|
|
| MD5 |
7488fb563f4958bc72a9be7210a2ae6f
|
|
| BLAKE2b-256 |
c7dcebbe468e7a71073879b322968a02e37594343ca2cc4b3ba65baf4db60adb
|
File details
Details for the file loop_rate_limiters-1.2.0-py3-none-any.whl.
File metadata
- Download URL: loop_rate_limiters-1.2.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
482f720f409e05dfca8b7b63df180217afa9a51564def681853cb7370a020b74
|
|
| MD5 |
c3794c21a46106ab0d42d635232b0522
|
|
| BLAKE2b-256 |
e26dd56be57340baf2e6f6361386f4c21b8b5e001251c64af954787f8d01ec78
|