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
Release files for loop-rate-limiters 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| loop_rate_limiters-1.2.0.tar.gz | 35.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| loop_rate_limiters-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:46.5 kB
Release files / loop_rate_limiters-1.2.0.tar.gz
| Download URL | loop_rate_limiters-1.2.0.tar.gz |
|---|---|
| Size | 35.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7187ec1f76f282ee7166d85c8e29eb13dd850422577decaf7e6bfc803173b421
|
|
BLAKE2b-256 checksum How to use checksums |
c7dcebbe468e7a71073879b322968a02e37594343ca2cc4b3ba65baf4db60adb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.4
|
Release files / loop_rate_limiters-1.2.0-py3-none-any.whl
| Download URL | loop_rate_limiters-1.2.0-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
482f720f409e05dfca8b7b63df180217afa9a51564def681853cb7370a020b74
|
|
BLAKE2b-256 checksum How to use checksums |
e26dd56be57340baf2e6f6361386f4c21b8b5e001251c64af954787f8d01ec78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.4
|