跳转到主要内容

Python协程的节流器。

项目描述

https://img.shields.io/badge/license-BSD-blue.svg https://img.shields.io/pypi/v/aiothrottles.svg https://img.shields.io/pypi/pyversions/aiothrottles.svg https://readthedocs.org/projects/aiothrottles/badge/?version=latest

aiothrottles

aiothrottles同步原语旨在扩展asyncio同步原语

有关更多详细信息,请参阅aiothrottles文档

用法

Throttle实现了对asyncio任务的速率限制。Throttle可以用来保证对共享资源的有限访问。

使用Throttle的首选方式是使用async with语句

throttle = Throttle('3/s')

# ... later
async with throttle:
    # access shared state

它相当于

throttle  = Throttle('3/s')

# ... later
await throttle.acquire()
try:
    # access shared state
finally:
    throttle.release()

调用速率由rate参数确定。以下格式传递速率

  • "{整数限制}/{单位时间}"

  • "{限制的分子}/{限制的分母}{单位时间}"

rate示例

  • 4/s, 5/m, 6/h, 7/d

  • 1/second, 2/minute, 3/hour, 4/day

  • 1/3s, 12/37m, 1/5h, 8/3d

安装

pip install aiothrottles

python setup.py install

支持的Python版本

支持Python 3.6、3.7、3.8和3.9。

测试

运行所有测试。

python setup.py test

使用PyTest运行测试。

python -m pytest [-k TEST_NAME] [-m MARKER]

许可证

aiothrottles采用BSD 3-Clause许可证发布。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码发行版

aiothrottles-0.2.0.tar.gz (5.9 kB 查看哈希值)

上传时间 源代码

构建发行版

aiothrottles-0.2.0-py3-none-any.whl (6.1 kB 查看哈希值)

上传时间 Python 3

由以下组织支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面