All Projects → aio-libs → Async Timeout

aio-libs / Async Timeout

Licence: other
asyncio-compatible timeout class

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Async Timeout

aioethereum
Ethereum RPC client library for Python asyncio (PEP 3156)
Stars: ✭ 16 (-94.77%)
Mutual labels:  asyncio
Gaio
High performance async-io(proactor) networking for Golang。golangのための高性能非同期io(proactor)ネットワーキング
Stars: ✭ 272 (-11.11%)
Mutual labels:  asyncio
Aiodocker
Python Docker API client based on asyncio and aiohttp
Stars: ✭ 288 (-5.88%)
Mutual labels:  asyncio
gulag
A dev-oriented, production-geared osu! server implementation in modern py
Stars: ✭ 101 (-66.99%)
Mutual labels:  asyncio
Aiowebsocket
Async WebSocket Client. Advantage: Flexible Lighter and Faster
Stars: ✭ 263 (-14.05%)
Mutual labels:  asyncio
Python3 Concurrency Pics 02
爬取 www.mzitu.com 全站图片,截至目前共5162个图集,16.5万多张美女图片,使用 asyncio 和 aiohttp 实现的异步版本只需要不到2小时就能爬取完成。按日期创建图集目录,保存更合理。控制台只显示下载的进度条,详细信息保存在日志文件中。支持异常处理,不会终止爬虫程序。失败的请求,下次再执行爬虫程序时会自动下载
Stars: ✭ 275 (-10.13%)
Mutual labels:  asyncio
tukio
Tukio is an event based workflow generator library
Stars: ✭ 27 (-91.18%)
Mutual labels:  asyncio
Tormysql
The highest performance asynchronous MySQL driver by PyMySQL
Stars: ✭ 302 (-1.31%)
Mutual labels:  asyncio
Rumqtt
Mqtt ecosystem in rust
Stars: ✭ 264 (-13.73%)
Mutual labels:  asyncio
Aiologger
Asynchronous logging for python and asyncio
Stars: ✭ 284 (-7.19%)
Mutual labels:  asyncio
ssdp
Python asyncio library for Simple Service Discovery Protocol (SSDP).
Stars: ✭ 25 (-91.83%)
Mutual labels:  asyncio
Web Main
🎉 Ultimate Emoji Generator
Stars: ✭ 261 (-14.71%)
Mutual labels:  asyncio
Awesome Asyncio
A curated list of awesome Python asyncio frameworks, libraries, software and resources
Stars: ✭ 3,279 (+971.57%)
Mutual labels:  asyncio
aioesphomeapi
Python Client for ESPHome native API. Used by Home Assistant.
Stars: ✭ 52 (-83.01%)
Mutual labels:  asyncio
Sqlalchemy aio
Asyncio strategy for SQLAlchemy.
Stars: ✭ 299 (-2.29%)
Mutual labels:  asyncio
waiter
Delayed iteration for polling and retries.
Stars: ✭ 17 (-94.44%)
Mutual labels:  asyncio
Example Scalping
A working example algorithm for scalping strategy trading multiple stocks concurrently using python asyncio
Stars: ✭ 267 (-12.75%)
Mutual labels:  asyncio
Yacron
A modern Cron replacement that is Docker-friendly
Stars: ✭ 302 (-1.31%)
Mutual labels:  asyncio
Python Slack Sdk
Slack Developer Kit for Python
Stars: ✭ 3,307 (+980.72%)
Mutual labels:  asyncio
Aioresponses
Aioresponses is a helper for mock/fake web requests in python aiohttp package.
Stars: ✭ 278 (-9.15%)
Mutual labels:  asyncio

async-timeout

.. image:: https://travis-ci.com/aio-libs/async-timeout.svg?branch=master :target: https://travis-ci.com/aio-libs/async-timeout .. image:: https://codecov.io/gh/aio-libs/async-timeout/branch/master/graph/badge.svg :target: https://codecov.io/gh/aio-libs/async-timeout .. image:: https://img.shields.io/pypi/v/async-timeout.svg :target: https://pypi.python.org/pypi/async-timeout .. image:: https://badges.gitter.im/Join%20Chat.svg :target: https://gitter.im/aio-libs/Lobby :alt: Chat on Gitter

asyncio-compatible timeout context manager.

Usage example

The context manager is useful in cases when you want to apply timeout logic around block of code or in cases when asyncio.wait_for() is not suitable. Also it's much faster than asyncio.wait_for() because timeout doesn't create a new task.

The timeout(delay, *, loop=None) call returns a context manager that cancels a block on timeout expiring::

async with timeout(1.5): await inner()

  1. If inner() is executed faster than in 1.5 seconds nothing happens.
  2. Otherwise inner() is cancelled internally by sending asyncio.CancelledError into but asyncio.TimeoutError is raised outside of context manager scope.

timeout parameter could be None for skipping timeout functionality.

Alternatively, timeout_at(when) can be used for scheduling at the absolute time::

loop = asyncio.get_event_loop() now = loop.time()

async with timeout_at(now + 1.5): await inner()

Please note: it is not POSIX time but a time with undefined starting base, e.g. the time of the system power on.

Context manager has .expired property for check if timeout happens exactly in context manager::

async with timeout(1.5) as cm: await inner() print(cm.expired)

The property is True if inner() execution is cancelled by timeout context manager.

If inner() call explicitly raises TimeoutError cm.expired is False.

The scheduled deadline time is available as .deadline property::

async with timeout(1.5) as cm: cm.deadline

Not finished yet timeout can be rescheduled by shift_by() or shift_to() methods::

async with timeout(1.5) as cm: cm.shift_by(1) # add another second on waiting cm.shift_to(loop.time() + 5) # reschedule to now+5 seconds

Rescheduling is forbidden if the timeout is expired or after exit from async with code block.

Installation

::

$ pip install async-timeout

The library is Python 3 only!

Authors and License

The module is written by Andrew Svetlov.

It's Apache 2 licensed and freely available.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].