Skip to main content

Loop frequency regulator for asyncio.

Project description

aiorate

Build Coverage Documentation PyPI version

Loop frequency regulator for asyncio with an API similar to rospy.Rate.

This project is archived as it has been superseded by loop-rate-limiters.

Installation

pip install aiorate

Usage

The Rate class provides a non-blocking loop frequency limiter:

  • Set the loop frequency in Hz at construction: rate = aiorate.Rate(200.0)
  • Call await rate.sleep() at every loop cycle

Here is what it looks like in practice:

import asyncio
import aiorate

async def main():
    rate = aiorate.Rate(400.0)  # Hz
    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())

Check out the examples folder for more advance use cases, such as multiple loops running simultaneously at different rates.

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

aiorate-1.0.2.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

aiorate-1.0.2-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file aiorate-1.0.2.tar.gz.

File metadata

  • Download URL: aiorate-1.0.2.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for aiorate-1.0.2.tar.gz
Algorithm Hash digest
SHA256 5d3f2d4f84de533ebfb902a4f4d3c3057f455ccbd2b261a76cb8f653105aa1eb
MD5 06d6a006b9b71fe9bc443f32aec9337f
BLAKE2b-256 d2c1317c3d4c2d2f8ade5ee731e4ee1b6df1444ebffe0d19a83cc4912187248c

See more details on using hashes here.

File details

Details for the file aiorate-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: aiorate-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for aiorate-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d6fdf4e90463f1ce5441709fc50129d84f314ce1a788acafaa79d0ee0cd4af38
MD5 e8f228618b5d4bb2b42a690201ddeb32
BLAKE2b-256 ddd4dc52c148fd12f95d14a0edf32fad83123bed1dac99bfaf61aad7a0df2921

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