METADATA 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. Metadata-Version: 2.1
  2. Name: async-timeout
  3. Version: 5.0.1
  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. Requires-Python: >=3.8
  23. Description-Content-Type: text/x-rst
  24. License-File: LICENSE
  25. async-timeout
  26. =============
  27. .. image:: https://travis-ci.com/aio-libs/async-timeout.svg?branch=master
  28. :target: https://travis-ci.com/aio-libs/async-timeout
  29. .. image:: https://codecov.io/gh/aio-libs/async-timeout/branch/master/graph/badge.svg
  30. :target: https://codecov.io/gh/aio-libs/async-timeout
  31. .. image:: https://img.shields.io/pypi/v/async-timeout.svg
  32. :target: https://pypi.python.org/pypi/async-timeout
  33. .. image:: https://badges.gitter.im/Join%20Chat.svg
  34. :target: https://gitter.im/aio-libs/Lobby
  35. :alt: Chat on Gitter
  36. asyncio-compatible timeout context manager.
  37. DEPRECATED
  38. ----------
  39. This library has effectively been upstreamed into Python 3.11+.
  40. Therefore this library is considered deprecated and no longer actively supported.
  41. Version 5.0+ provides dual-mode when executed on Python 3.11+:
  42. ``asyncio_timeout.Timeout`` is fully compatible with ``asyncio.Timeout`` *and* old
  43. versions of the library.
  44. Anyway, using upstream is highly recommended. ``asyncio_timeout`` exists only for the
  45. sake of backward compatibility, easy supporting both old and new Python by the same
  46. code, and easy misgration.
  47. If rescheduling API is not important and only ``async with timeout(...): ...`` functionality is required,
  48. a user could apply conditional import::
  49. if sys.version_info >= (3, 11):
  50. from asyncio import timeout, timeout_at
  51. else:
  52. from async_timeout import timeout, timeout_at
  53. Usage example
  54. -------------
  55. The context manager is useful in cases when you want to apply timeout
  56. logic around block of code or in cases when ``asyncio.wait_for()`` is
  57. not suitable. Also it's much faster than ``asyncio.wait_for()``
  58. because ``timeout`` doesn't create a new task.
  59. The ``timeout(delay, *, loop=None)`` call returns a context manager
  60. that cancels a block on *timeout* expiring::
  61. from async_timeout import timeout
  62. async with timeout(1.5):
  63. await inner()
  64. 1. If ``inner()`` is executed faster than in ``1.5`` seconds nothing
  65. happens.
  66. 2. Otherwise ``inner()`` is cancelled internally by sending
  67. ``asyncio.CancelledError`` into but ``asyncio.TimeoutError`` is
  68. raised outside of context manager scope.
  69. *timeout* parameter could be ``None`` for skipping timeout functionality.
  70. Alternatively, ``timeout_at(when)`` can be used for scheduling
  71. at the absolute time::
  72. loop = asyncio.get_event_loop()
  73. now = loop.time()
  74. async with timeout_at(now + 1.5):
  75. await inner()
  76. Please note: it is not POSIX time but a time with
  77. undefined starting base, e.g. the time of the system power on.
  78. Context manager has ``.expired()`` / ``.expired`` for check if timeout happens
  79. exactly in context manager::
  80. async with timeout(1.5) as cm:
  81. await inner()
  82. print(cm.expired()) # recommended api
  83. print(cm.expired) # compatible api
  84. The property is ``True`` if ``inner()`` execution is cancelled by
  85. timeout context manager.
  86. If ``inner()`` call explicitly raises ``TimeoutError`` ``cm.expired``
  87. is ``False``.
  88. The scheduled deadline time is available as ``.when()`` / ``.deadline``::
  89. async with timeout(1.5) as cm:
  90. cm.when() # recommended api
  91. cm.deadline # compatible api
  92. Not finished yet timeout can be rescheduled by ``shift()``
  93. or ``update()`` methods::
  94. async with timeout(1.5) as cm:
  95. # recommended api
  96. cm.reschedule(cm.when() + 1) # add another second on waiting
  97. # compatible api
  98. cm.shift(1) # add another second on waiting
  99. cm.update(loop.time() + 5) # reschedule to now+5 seconds
  100. Rescheduling is forbidden if the timeout is expired or after exit from ``async with``
  101. code block.
  102. Disable scheduled timeout::
  103. async with timeout(1.5) as cm:
  104. cm.reschedule(None) # recommended api
  105. cm.reject() # compatible api
  106. Installation
  107. ------------
  108. ::
  109. $ pip install async-timeout
  110. The library is Python 3 only!
  111. Authors and License
  112. -------------------
  113. The module is written by Andrew Svetlov.
  114. It's *Apache 2* licensed and freely available.