From 42bf0eb276980576fc4715a5a2025d04d7eb930f Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Mon, 8 Aug 2022 08:51:48 +0200 Subject: [PATCH] Deprecated loop argument to timeout(). --- CHANGELOG.txt | 5 +++++ asgiref/timeout.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 0c2c2063..0a4f1c85 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,11 @@ UNRELEASED ---------- +* The ``loop`` argument to ``asgiref.timeout.timeout`` is deprecated. As per other + ``asyncio`` based APIs, the running event loop is used by default. Note that + ``asyncio`` provides timeout utilities from Python 3.11, and these should be + preferred where available. + * Support for the ``ASGI_THREADS`` environment variable, used by ``SyncToAsync``, is removed. In general, a running event-loop is not available to `asgiref` at import time, and so the default thread pool diff --git a/asgiref/timeout.py b/asgiref/timeout.py index f0ce7b42..fd5381d0 100644 --- a/asgiref/timeout.py +++ b/asgiref/timeout.py @@ -7,6 +7,7 @@ import asyncio +import warnings from types import TracebackType from typing import Any # noqa from typing import Optional, Type @@ -36,6 +37,10 @@ def __init__( self._timeout = timeout if loop is None: loop = asyncio.get_running_loop() + else: + warnings.warn( + """The loop argument to timeout() is deprecated.""", DeprecationWarning + ) self._loop = loop self._task = None # type: Optional[asyncio.Task[Any]] self._cancelled = False