Skip to content

Commit ea79016

Browse files
Updated timeout helper to use get_running_loop(). (#337)
* Update timeout helper to use get_running_loop(). * Deprecated loop argument to timeout().
1 parent 36f37c9 commit ea79016

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGELOG.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
UNRELEASED
22
----------
33

4+
* The ``loop`` argument to ``asgiref.timeout.timeout`` is deprecated. As per other
5+
``asyncio`` based APIs, the running event loop is used by default. Note that
6+
``asyncio`` provides timeout utilities from Python 3.11, and these should be
7+
preferred where available.
8+
49
* Support for the ``ASGI_THREADS`` environment variable, used by
510
``SyncToAsync``, is removed. In general, a running event-loop is not
611
available to `asgiref` at import time, and so the default thread pool

asgiref/timeout.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
import asyncio
10+
import warnings
1011
from types import TracebackType
1112
from typing import Any # noqa
1213
from typing import Optional, Type
@@ -35,7 +36,11 @@ def __init__(
3536
) -> None:
3637
self._timeout = timeout
3738
if loop is None:
38-
loop = asyncio.get_event_loop()
39+
loop = asyncio.get_running_loop()
40+
else:
41+
warnings.warn(
42+
"""The loop argument to timeout() is deprecated.""", DeprecationWarning
43+
)
3944
self._loop = loop
4045
self._task = None # type: Optional[asyncio.Task[Any]]
4146
self._cancelled = False

0 commit comments

Comments
 (0)