Skip to main content

Loop rate limiters

Build Documentation Coverage Conda version PyPI version

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)

Source distribution for loop-rate-limiters 1.2.0
File Size Uploaded
loop_rate_limiters-1.2.0.tar.gz 35.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for loop-rate-limiters 1.2.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page