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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loop_rate_limiters-1.2.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

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

Hashes for loop_rate_limiters-1.2.0.tar.gz
Algorithm Hash digest
SHA256 7187ec1f76f282ee7166d85c8e29eb13dd850422577decaf7e6bfc803173b421
MD5 7488fb563f4958bc72a9be7210a2ae6f
BLAKE2b-256 c7dcebbe468e7a71073879b322968a02e37594343ca2cc4b3ba65baf4db60adb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for loop_rate_limiters-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 482f720f409e05dfca8b7b63df180217afa9a51564def681853cb7370a020b74
MD5 c3794c21a46106ab0d42d635232b0522
BLAKE2b-256 e26dd56be57340baf2e6f6361386f4c21b8b5e001251c64af954787f8d01ec78

See more details on using hashes here.

Supported by

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