Skip to main content

Loop rate limiters.

Project description

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

Project details


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.1.2.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

loop_rate_limiters-1.1.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file loop_rate_limiters-1.1.2.tar.gz.

File metadata

  • Download URL: loop_rate_limiters-1.1.2.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for loop_rate_limiters-1.1.2.tar.gz
Algorithm Hash digest
SHA256 145cad53fffcf45f3a5305b150896484585753366b52c00cceea7a0f53a19585
MD5 84fbebe27f88d718ae3e930b581c8702
BLAKE2b-256 f06501c16cd4c363d3b2368e204b5c8b5e9de57148fc2dd533d6939ffb869cac

See more details on using hashes here.

File details

Details for the file loop_rate_limiters-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for loop_rate_limiters-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c0c56282121e539cea8debd51fb98562e85162f711c30e30615f7ccf92aad643
MD5 08edac8a9d6d781a466e9b75f9fe0c4c
BLAKE2b-256 54e071ef5c58e2fc2b81174834002b2998d65f3e3b40d09309b5d77e33cde0b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page