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::
from async_timeout import timeout
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(1) # add another second on waiting
cm.update(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.
Raw data
{
"_id": null,
"home_page": "https://github.com/aio-libs/async-timeout",
"name": "async-timeout",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Andrew Svetlov <andrew.svetlov@gmail.com>",
"author_email": "andrew.svetlov@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/87/d6/21b30a550dafea84b1b8eee21b5e23fa16d010ae006011221f33dcd8d7f8/async-timeout-4.0.3.tar.gz",
"platform": null,
"description": "async-timeout\n=============\n.. image:: https://travis-ci.com/aio-libs/async-timeout.svg?branch=master\n :target: https://travis-ci.com/aio-libs/async-timeout\n.. image:: https://codecov.io/gh/aio-libs/async-timeout/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/aio-libs/async-timeout\n.. image:: https://img.shields.io/pypi/v/async-timeout.svg\n :target: https://pypi.python.org/pypi/async-timeout\n.. image:: https://badges.gitter.im/Join%20Chat.svg\n :target: https://gitter.im/aio-libs/Lobby\n :alt: Chat on Gitter\n\nasyncio-compatible timeout context manager.\n\n\nUsage example\n-------------\n\n\nThe context manager is useful in cases when you want to apply timeout\nlogic around block of code or in cases when ``asyncio.wait_for()`` is\nnot suitable. Also it's much faster than ``asyncio.wait_for()``\nbecause ``timeout`` doesn't create a new task.\n\nThe ``timeout(delay, *, loop=None)`` call returns a context manager\nthat cancels a block on *timeout* expiring::\n\n from async_timeout import timeout\n async with timeout(1.5):\n await inner()\n\n1. If ``inner()`` is executed faster than in ``1.5`` seconds nothing\n happens.\n2. Otherwise ``inner()`` is cancelled internally by sending\n ``asyncio.CancelledError`` into but ``asyncio.TimeoutError`` is\n raised outside of context manager scope.\n\n*timeout* parameter could be ``None`` for skipping timeout functionality.\n\n\nAlternatively, ``timeout_at(when)`` can be used for scheduling\nat the absolute time::\n\n loop = asyncio.get_event_loop()\n now = loop.time()\n\n async with timeout_at(now + 1.5):\n await inner()\n\n\nPlease note: it is not POSIX time but a time with\nundefined starting base, e.g. the time of the system power on.\n\n\nContext manager has ``.expired`` property for check if timeout happens\nexactly in context manager::\n\n async with timeout(1.5) as cm:\n await inner()\n print(cm.expired)\n\nThe property is ``True`` if ``inner()`` execution is cancelled by\ntimeout context manager.\n\nIf ``inner()`` call explicitly raises ``TimeoutError`` ``cm.expired``\nis ``False``.\n\nThe scheduled deadline time is available as ``.deadline`` property::\n\n async with timeout(1.5) as cm:\n cm.deadline\n\nNot finished yet timeout can be rescheduled by ``shift_by()``\nor ``shift_to()`` methods::\n\n async with timeout(1.5) as cm:\n cm.shift(1) # add another second on waiting\n cm.update(loop.time() + 5) # reschedule to now+5 seconds\n\nRescheduling is forbidden if the timeout is expired or after exit from ``async with``\ncode block.\n\n\nInstallation\n------------\n\n::\n\n $ pip install async-timeout\n\nThe library is Python 3 only!\n\n\n\nAuthors and License\n-------------------\n\nThe module is written by Andrew Svetlov.\n\nIt's *Apache 2* licensed and freely available.\n",
"bugtrack_url": null,
"license": "Apache 2",
"summary": "Timeout context manager for asyncio programs",
"version": "4.0.3",
"project_urls": {
"CI: GitHub Actions": "https://github.com/aio-libs/async-timeout/actions",
"Chat: Gitter": "https://gitter.im/aio-libs/Lobby",
"Coverage: codecov": "https://codecov.io/github/aio-libs/async-timeout",
"GitHub: issues": "https://github.com/aio-libs/async-timeout/issues",
"GitHub: repo": "https://github.com/aio-libs/async-timeout",
"Homepage": "https://github.com/aio-libs/async-timeout"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a7fae01228c2938de91d47b307831c62ab9e4001e747789d0b05baf779a6488c",
"md5": "f3603f8a42fadfe34821308efe7e8431",
"sha256": "7405140ff1230c310e51dc27b3145b9092d659ce68ff733fb0cefe3ee42be028"
},
"downloads": -1,
"filename": "async_timeout-4.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f3603f8a42fadfe34821308efe7e8431",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 5721,
"upload_time": "2023-08-10T16:35:55",
"upload_time_iso_8601": "2023-08-10T16:35:55.203899Z",
"url": "https://files.pythonhosted.org/packages/a7/fa/e01228c2938de91d47b307831c62ab9e4001e747789d0b05baf779a6488c/async_timeout-4.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "87d621b30a550dafea84b1b8eee21b5e23fa16d010ae006011221f33dcd8d7f8",
"md5": "9bf7b764a7310cb063c1c261c21342e4",
"sha256": "4640d96be84d82d02ed59ea2b7105a0f7b33abe8703703cd0ab0bf87c427522f"
},
"downloads": -1,
"filename": "async-timeout-4.0.3.tar.gz",
"has_sig": false,
"md5_digest": "9bf7b764a7310cb063c1c261c21342e4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 8345,
"upload_time": "2023-08-10T16:35:56",
"upload_time_iso_8601": "2023-08-10T16:35:56.907296Z",
"url": "https://files.pythonhosted.org/packages/87/d6/21b30a550dafea84b1b8eee21b5e23fa16d010ae006011221f33dcd8d7f8/async-timeout-4.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-10 16:35:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aio-libs",
"github_project": "async-timeout",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "async-timeout"
}