METADATA 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. Metadata-Version: 2.1
  2. Name: async-timeout
  3. Version: 4.0.3
  4. Summary: Timeout context manager for asyncio programs
  5. Home-page: https://github.com/aio-libs/async-timeout
  6. Author: Andrew Svetlov <andrew.svetlov@gmail.com>
  7. Author-email: andrew.svetlov@gmail.com
  8. License: Apache 2
  9. Project-URL: Chat: Gitter, https://gitter.im/aio-libs/Lobby
  10. Project-URL: CI: GitHub Actions, https://github.com/aio-libs/async-timeout/actions
  11. Project-URL: Coverage: codecov, https://codecov.io/github/aio-libs/async-timeout
  12. Project-URL: GitHub: issues, https://github.com/aio-libs/async-timeout/issues
  13. Project-URL: GitHub: repo, https://github.com/aio-libs/async-timeout
  14. Classifier: Development Status :: 5 - Production/Stable
  15. Classifier: Topic :: Software Development :: Libraries
  16. Classifier: Framework :: AsyncIO
  17. Classifier: Intended Audience :: Developers
  18. Classifier: License :: OSI Approved :: Apache Software License
  19. Classifier: Programming Language :: Python
  20. Classifier: Programming Language :: Python :: 3
  21. Classifier: Programming Language :: Python :: 3 :: Only
  22. Classifier: Programming Language :: Python :: 3.7
  23. Classifier: Programming Language :: Python :: 3.8
  24. Classifier: Programming Language :: Python :: 3.9
  25. Classifier: Programming Language :: Python :: 3.10
  26. Classifier: Programming Language :: Python :: 3.11
  27. Requires-Python: >=3.7
  28. Description-Content-Type: text/x-rst
  29. License-File: LICENSE
  30. Requires-Dist: typing-extensions >=3.6.5 ; python_version < "3.8"
  31. async-timeout
  32. =============
  33. .. image:: https://travis-ci.com/aio-libs/async-timeout.svg?branch=master
  34. :target: https://travis-ci.com/aio-libs/async-timeout
  35. .. image:: https://codecov.io/gh/aio-libs/async-timeout/branch/master/graph/badge.svg
  36. :target: https://codecov.io/gh/aio-libs/async-timeout
  37. .. image:: https://img.shields.io/pypi/v/async-timeout.svg
  38. :target: https://pypi.python.org/pypi/async-timeout
  39. .. image:: https://badges.gitter.im/Join%20Chat.svg
  40. :target: https://gitter.im/aio-libs/Lobby
  41. :alt: Chat on Gitter
  42. asyncio-compatible timeout context manager.
  43. Usage example
  44. -------------
  45. The context manager is useful in cases when you want to apply timeout
  46. logic around block of code or in cases when ``asyncio.wait_for()`` is
  47. not suitable. Also it's much faster than ``asyncio.wait_for()``
  48. because ``timeout`` doesn't create a new task.
  49. The ``timeout(delay, *, loop=None)`` call returns a context manager
  50. that cancels a block on *timeout* expiring::
  51. from async_timeout import timeout
  52. async with timeout(1.5):
  53. await inner()
  54. 1. If ``inner()`` is executed faster than in ``1.5`` seconds nothing
  55. happens.
  56. 2. Otherwise ``inner()`` is cancelled internally by sending
  57. ``asyncio.CancelledError`` into but ``asyncio.TimeoutError`` is
  58. raised outside of context manager scope.
  59. *timeout* parameter could be ``None`` for skipping timeout functionality.
  60. Alternatively, ``timeout_at(when)`` can be used for scheduling
  61. at the absolute time::
  62. loop = asyncio.get_event_loop()
  63. now = loop.time()
  64. async with timeout_at(now + 1.5):
  65. await inner()
  66. Please note: it is not POSIX time but a time with
  67. undefined starting base, e.g. the time of the system power on.
  68. Context manager has ``.expired`` property for check if timeout happens
  69. exactly in context manager::
  70. async with timeout(1.5) as cm:
  71. await inner()
  72. print(cm.expired)
  73. The property is ``True`` if ``inner()`` execution is cancelled by
  74. timeout context manager.
  75. If ``inner()`` call explicitly raises ``TimeoutError`` ``cm.expired``
  76. is ``False``.
  77. The scheduled deadline time is available as ``.deadline`` property::
  78. async with timeout(1.5) as cm:
  79. cm.deadline
  80. Not finished yet timeout can be rescheduled by ``shift_by()``
  81. or ``shift_to()`` methods::
  82. async with timeout(1.5) as cm:
  83. cm.shift(1) # add another second on waiting
  84. cm.update(loop.time() + 5) # reschedule to now+5 seconds
  85. Rescheduling is forbidden if the timeout is expired or after exit from ``async with``
  86. code block.
  87. Installation
  88. ------------
  89. ::
  90. $ pip install async-timeout
  91. The library is Python 3 only!
  92. Authors and License
  93. -------------------
  94. The module is written by Andrew Svetlov.
  95. It's *Apache 2* licensed and freely available.