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

You can install the library straight from PyPI:

$ pip install loop-rate-limiters

Or equivalently from Conda:

$ conda install -c conda-forge loop-rate-limiters

Asynchronous I/O

The AsyncRateLimiter class provides a loop frequency limiter 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()

if __name__ == "__main__":
    asyncio.run(main())

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

Uploaded Source

Built Distribution

loop_rate_limiters-1.0.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for loop_rate_limiters-1.0.0.tar.gz
Algorithm Hash digest
SHA256 589218f978421debe221eeadf4de3e64cff8c34c58bbaeb878e6326490f4f370
MD5 bdf91443df95a06fcd8ef16aaf80ad1b
BLAKE2b-256 95d86bc6854f0ad03623d42211ae45cba6913d23d471572a5ff9cc3c43371662

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for loop_rate_limiters-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1bec278411fc4d3f35a94f1342cf211e9ad81d8a3d3b9b08f2eeb5e4fd6e9e9d
MD5 60c53c659594c84ad38bdf0581470048
BLAKE2b-256 92ad3cd3e1992e79bbc535dcf8ea5591bed7967d6fe2437fbc737f3f14898b6b

See more details on using hashes here.

Supported by

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