aiodecorator-1.0.2
توضیحات
Python decorators for asyncio
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | aiodecorator-1.0.2 |
| نام | aiodecorator |
| نسخه کتابخانه | 1.0.2 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | kaelzhang |
| ایمیل نویسنده | - |
| آدرس صفحه اصلی | https://github.com/kaelzhang/python-aiodecorator |
| آدرس اینترنتی | https://pypi.org/project/aiodecorator/ |
| مجوز | MIT |
[](https://travis-ci.org/kaelzhang/python-aiodecorator)
[](https://codecov.io/gh/kaelzhang/python-aiodecorator)
[](https://pypi.org/project/aiodecorator/)
[](https://github.com/kaelzhang/python-aiodecorator)
# aiodecorator
Python decorators for asyncio, including
- **throttle**: Throttle a (coroutine) function that return an `Awaitable`
<!-- - limit -->
<!-- - timeout -->
## Install
```sh
$ pip install aiodecorator
```
## Usage
```py
import time
import asyncio
from aiodecorator import (
throttle
)
now = time.time()
# -----------------------------------------------------
# The throttled function is only called twice a second
@throttle(2, 1)
async def throttled(index: int):
diff = format(time.time - now, '.0f')
print(index, f'{diff}s')
# -----------------------------------------------------
async def main():
loop = asyncio.get_running_loop()
tasks = [
loop.create_task(throttled(index))
for index in range(5)
]
await asyncio.wait(tasks)
asyncio.run(main())
# Output
# 0 0s
# 1 0s
# 2 1s
# 3 1s
# 4 2s
```
## APIs
### throttle(limit: int, interval: Union[float, int])
- **limit** `int` Maximum number of calls within an `interval`.
- **interval** `Union[int, float]` Timespan for limit in seconds.
Returns a decorator function
## License
[MIT](LICENSE)
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.6 | Python |
نحوه نصب
نصب پکیج whl aiodecorator-1.0.2:
pip install aiodecorator-1.0.2.whl
نصب پکیج tar.gz aiodecorator-1.0.2:
pip install aiodecorator-1.0.2.tar.gz