diff --git a/synapse/handlers/auth.py b/synapse/handlers/auth.py index 8f5df65e4e..89163b615d 100644 --- a/synapse/handlers/auth.py +++ b/synapse/handlers/auth.py @@ -43,7 +43,7 @@ import unpaddedbase64 from prometheus_client import Counter try: - from twisted.internet.defer import CancelledError + from asyncio import CancelledError from twisted.web.server import Request except ImportError: pass diff --git a/synapse/logging/_remote.py b/synapse/logging/_remote.py index 0ac1f584b4..300d1e10a4 100644 --- a/synapse/logging/_remote.py +++ b/synapse/logging/_remote.py @@ -36,7 +36,7 @@ except ImportError: try: from twisted.application.internet import ClientService - from twisted.internet.defer import CancelledError + from asyncio import CancelledError from twisted.internet.defer import Deferred from twisted.internet.endpoints import ( HostnameEndpoint, diff --git a/synapse/types/__init__.py b/synapse/types/__init__.py index 09c71dfab0..400b5144aa 100644 --- a/synapse/types/__init__.py +++ b/synapse/types/__init__.py @@ -59,7 +59,7 @@ except ImportError: pass try: - from twisted.internet.defer import CancelledError + from asyncio import CancelledError from twisted.internet.interfaces import ( IReactorCore, IReactorPluggableNameResolver, diff --git a/synapse/util/async_helpers.py b/synapse/util/async_helpers.py index 80e1d5a944..97c6197252 100644 --- a/synapse/util/async_helpers.py +++ b/synapse/util/async_helpers.py @@ -1146,7 +1146,8 @@ class NativeLinearizer: # do work """ - def __init__(self, name: str, max_count: int = 1) -> None: + def __init__(self, name: str, max_count: int = 1, clock: Any = None) -> None: + # clock parameter accepted for backward compatibility with Linearizer(clock=...) self.name = name self.max_count = max_count self._key_to_entry: dict[Hashable, _NativeLinearizerEntry] = {} @@ -1350,7 +1351,8 @@ class NativeAwakenableSleeper: Allows explicit waking of sleeping coroutines by name. """ - def __init__(self) -> None: + def __init__(self, clock: Any = None) -> None: + # clock parameter accepted for backward compatibility self._streams: dict[str, set[asyncio.Event]] = {} def wake(self, name: str) -> None: @@ -1383,7 +1385,8 @@ class NativeEvent: Like threading.Event but for asyncio code. """ - def __init__(self) -> None: + def __init__(self, clock: Any = None) -> None: + # clock parameter accepted for backward compatibility self._event = asyncio.Event() def set(self) -> None: @@ -1490,3 +1493,12 @@ class DeferredEvent: pass return self.is_set() + + +# =========================================================================== +# The native asyncio versions (NativeLinearizer, NativeReadWriteLock, +# NativeAwakenableSleeper, NativeEvent) are available above and will replace +# the Deferred-based versions once the entry point switches from reactor.run() +# to asyncio.run(). Until then, the old classes remain as they need the +# Twisted reactor to drive their Deferred-based internals. +# ===========================================================================