loop-rate-limiters


Nameloop-rate-limiters JSON
Version 1.1.0 PyPI version JSON
download
home_pageNone
SummaryLoop rate limiters.
upload_time2024-12-18 15:11:06
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords rate loop frequency regulator limiter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Loop rate limiters

[![Build](https://img.shields.io/github/actions/workflow/status/stephane-caron/loop-rate-limiters/main.yml?branch=main)](https://github.com/stephane-caron/loop-rate-limiters/actions)
[![Documentation](https://img.shields.io/github/actions/workflow/status/stephane-caron/loop-rate-limiters/docs.yml?branch=main&label=docs)](https://upkie.github.io/loop-rate-limiters/)
[![Coverage](https://coveralls.io/repos/github/stephane-caron/loop-rate-limiters/badge.svg?branch=main)](https://coveralls.io/github/stephane-caron/loop-rate-limiters?branch=main)
[![Conda version](https://img.shields.io/conda/vn/conda-forge/loop-rate-limiters.svg)](https://anaconda.org/conda-forge/loop-rate-limiters)
[![PyPI version](https://img.shields.io/pypi/v/loop-rate-limiters)](https://pypi.org/project/loop-rate-limiters/)

Simple loop frequency regulators in Python with an API similar to ``rospy.Rate``:

```python
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](https://github.com/stephane-caron/loop-rate-limiters#asynchronous-io).

## Installation

### From conda-forge

```console
conda install -c conda-forge loop-rate-limiters
```

### From PyPI

```console
pip install loop-rate-limiters
```

## Asynchronous I/O

The ``AsyncRateLimiter`` class provides a loop frequency limiter for [asyncio](https://docs.python.org/3/library/asyncio.html):

```python
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 if, for instance, there are several tasks executed in parallel at different frequencies.

## See also

- [ischedule](https://github.com/aleksve/ischedule): single-thread interval scheduler in Python

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "loop-rate-limiters",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "St\u00e9phane Caron <stephane.caron@normalesup.org>",
    "keywords": "rate, loop, frequency, regulator, limiter",
    "author": null,
    "author_email": "St\u00e9phane Caron <stephane.caron@normalesup.org>",
    "download_url": "https://files.pythonhosted.org/packages/5f/e1/0431a29de33dd7fe7ee3d107c47d05aa2b3ebfb3bdb6b4023e11465cfd3b/loop_rate_limiters-1.1.0.tar.gz",
    "platform": null,
    "description": "# Loop rate limiters\n\n[![Build](https://img.shields.io/github/actions/workflow/status/stephane-caron/loop-rate-limiters/main.yml?branch=main)](https://github.com/stephane-caron/loop-rate-limiters/actions)\n[![Documentation](https://img.shields.io/github/actions/workflow/status/stephane-caron/loop-rate-limiters/docs.yml?branch=main&label=docs)](https://upkie.github.io/loop-rate-limiters/)\n[![Coverage](https://coveralls.io/repos/github/stephane-caron/loop-rate-limiters/badge.svg?branch=main)](https://coveralls.io/github/stephane-caron/loop-rate-limiters?branch=main)\n[![Conda version](https://img.shields.io/conda/vn/conda-forge/loop-rate-limiters.svg)](https://anaconda.org/conda-forge/loop-rate-limiters)\n[![PyPI version](https://img.shields.io/pypi/v/loop-rate-limiters)](https://pypi.org/project/loop-rate-limiters/)\n\nSimple loop frequency regulators in Python with an API similar to ``rospy.Rate``:\n\n```python\nfrom loop_rate_limiters import RateLimiter\nfrom time import perf_counter\n\nrate = RateLimiter(frequency=400.0)\nwhile True:\n    print(f\"Hello from loop at {perf_counter():.3f} s\")\n    rate.sleep()\n```\n\nA similar ``AsyncRateLimiter`` class is available for [asynchronous code](https://github.com/stephane-caron/loop-rate-limiters#asynchronous-io).\n\n## Installation\n\n### From conda-forge\n\n```console\nconda install -c conda-forge loop-rate-limiters\n```\n\n### From PyPI\n\n```console\npip install loop-rate-limiters\n```\n\n## Asynchronous I/O\n\nThe ``AsyncRateLimiter`` class provides a loop frequency limiter for [asyncio](https://docs.python.org/3/library/asyncio.html):\n\n```python\nimport asyncio\nfrom loop_rate_limiters import AsyncRateLimiter\n\nasync def main():\n    rate = AsyncRateLimiter(frequency=400.0)\n    while True:\n        loop_time = asyncio.get_event_loop().time()\n        print(f\"Hello from loop at {loop_time:.3f} s\")\n        await rate.sleep()\n\nasyncio.run(main())\n```\n\nThis can be used if, for instance, there are several tasks executed in parallel at different frequencies.\n\n## See also\n\n- [ischedule](https://github.com/aleksve/ischedule): single-thread interval scheduler in Python\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Loop rate limiters.",
    "version": "1.1.0",
    "project_urls": {
        "Changelog": "https://github.com/stephane-caron/loop-rate-limiters/blob/master/CHANGELOG.md",
        "Homepage": "https://github.com/stephane-caron/loop-rate-limiters",
        "Source": "https://github.com/stephane-caron/loop-rate-limiters",
        "Tracker": "https://github.com/stephane-caron/loop-rate-limiters/issues"
    },
    "split_keywords": [
        "rate",
        " loop",
        " frequency",
        " regulator",
        " limiter"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9189d98a731a5f5efca86052c45bcf4479cbeee2994f559e3bc0bd312e7840cf",
                "md5": "23ecb59a49147c7c81f9686c3eb3272b",
                "sha256": "7dc8c4120d81c58d15c59d19eb0602e0a245bb6fb361b76b2e5898285757a6b2"
            },
            "downloads": -1,
            "filename": "loop_rate_limiters-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "23ecb59a49147c7c81f9686c3eb3272b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 9767,
            "upload_time": "2024-12-18T15:11:03",
            "upload_time_iso_8601": "2024-12-18T15:11:03.953660Z",
            "url": "https://files.pythonhosted.org/packages/91/89/d98a731a5f5efca86052c45bcf4479cbeee2994f559e3bc0bd312e7840cf/loop_rate_limiters-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5fe10431a29de33dd7fe7ee3d107c47d05aa2b3ebfb3bdb6b4023e11465cfd3b",
                "md5": "3b4b8b838b38a5171c3bb6b4501b01a1",
                "sha256": "31af950fc29739679c733d1f6b43740b0b63715347f1dd5069a8a4810bb72921"
            },
            "downloads": -1,
            "filename": "loop_rate_limiters-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3b4b8b838b38a5171c3bb6b4501b01a1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 11996,
            "upload_time": "2024-12-18T15:11:06",
            "upload_time_iso_8601": "2024-12-18T15:11:06.785092Z",
            "url": "https://files.pythonhosted.org/packages/5f/e1/0431a29de33dd7fe7ee3d107c47d05aa2b3ebfb3bdb6b4023e11465cfd3b/loop_rate_limiters-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-18 15:11:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stephane-caron",
    "github_project": "loop-rate-limiters",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "loop-rate-limiters"
}
        
Elapsed time: 0.38086s