From d2f8c7ebdd1d0025c7af0a9b346b833fd3ee567e Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Fri, 9 Sep 2022 21:19:03 -0500 Subject: [PATCH] Increase compatibility with older dependency versions I can't remember the precise reason for these various changes or whether they're still needed. --- strikebot/src/strikebot/__init__.py | 2 +- strikebot/src/strikebot/__main__.py | 7 ++++++- strikebot/src/strikebot/db.py | 2 +- strikebot/src/strikebot/live_ws.py | 8 ++++---- strikebot/src/strikebot/queue.py | 5 ++++- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/strikebot/src/strikebot/__init__.py b/strikebot/src/strikebot/__init__.py index 7c37d14..4c7c496 100644 --- a/strikebot/src/strikebot/__init__.py +++ b/strikebot/src/strikebot/__init__.py @@ -215,7 +215,7 @@ async def count_tracker_impl( if not _READ_ONLY and update.command is Command.REPORT: api_pool.enqueue_request(ReportUpdateRequest(thread_id, body = _format_curr_count(last_valid))) - with message_rx: + async with message_rx: while True: if buffer_: deadline = min(bu.release_at for bu in buffer_) diff --git a/strikebot/src/strikebot/__main__.py b/strikebot/src/strikebot/__main__.py index 4c2b1d9..ac490b6 100644 --- a/strikebot/src/strikebot/__main__.py +++ b/strikebot/src/strikebot/__main__.py @@ -12,7 +12,12 @@ import datetime as dt import logging from trio import open_memory_channel, open_nursery, open_signal_receiver -from trio.lowlevel import current_root_task, Task + +try: + from trio.lowlevel import current_root_task, Task +except ImportError: + from trio.hazmat import current_root_task, Task + import trio_asyncio import triopg diff --git a/strikebot/src/strikebot/db.py b/strikebot/src/strikebot/db.py index c9a060a..d1a2f42 100644 --- a/strikebot/src/strikebot/db.py +++ b/strikebot/src/strikebot/db.py @@ -9,7 +9,7 @@ import trio def _channel_sender(method): async def wrapped(self, resp_channel, *args, **kwargs): ret = await method(self, *args, **kwargs) - with resp_channel: + async with resp_channel: await resp_channel.send(ret) return wrapped diff --git a/strikebot/src/strikebot/live_ws.py b/strikebot/src/strikebot/live_ws.py index cb8b3d0..031d652 100644 --- a/strikebot/src/strikebot/live_ws.py +++ b/strikebot/src/strikebot/live_ws.py @@ -74,7 +74,7 @@ class HealingReadPool: try: async with conn_ctx as conn: self._logger.debug("scope up: {}".format(obj_digest(cancel_scope))) - with refresh_tx: + async with refresh_tx: silent_timeout = False with cancel_scope, suppress(ConnectionClosed): while True: @@ -135,7 +135,7 @@ class HealingReadPool: async def conn_refresher_impl(self): """Task to monitor and replace WS connections as they disconnect or go silent.""" - with self._refresh_queue_rx: + async with self._refresh_queue_rx: async for old_scope in self._refresh_queue_rx: await self._pool_event_tx.send(_ConnectionDown(trio.current_time(), old_scope)) await self._spawn_reader() @@ -179,7 +179,7 @@ class PoolMerger: async def event_reader_impl(self): """Drop unused messages, deduplicate useful ones, and communicate with the timeout handler.""" - with self._pool_event_rx, self._timer_poke_tx: + async with self._pool_event_rx, self._timer_poke_tx: async for event in self._pool_event_rx: if isinstance(event, _ConnectionUp): # An early add of an active scope could mean it's expected on a message that fired before it opened, @@ -224,7 +224,7 @@ class PoolMerger: async def timeout_handler_impl(self): """When connections have had enough time to reach parity on a message, signal replacement of any slackers.""" - with self._timer_poke_rx: + async with self._timer_poke_rx: while True: if self._buckets: now = trio.current_time() diff --git a/strikebot/src/strikebot/queue.py b/strikebot/src/strikebot/queue.py index adfbbe6..acf5ef0 100644 --- a/strikebot/src/strikebot/queue.py +++ b/strikebot/src/strikebot/queue.py @@ -6,7 +6,10 @@ from functools import total_ordering from typing import Any, Iterable import heapq -from trio.lowlevel import ParkingLot +try: + from trio.lowlevel import ParkingLot +except ImportError: + from trio.hazmat import ParkingLot class Queue: -- 2.30.2