Increase compatibility with older dependency versions
authorJakob Cornell <jakob+gpg@jcornell.net>
Sat, 10 Sep 2022 02:19:03 +0000 (21:19 -0500)
committerJakob Cornell <jakob+gpg@jcornell.net>
Sat, 10 Sep 2022 02:19:03 +0000 (21:19 -0500)
I can't remember the precise reason for these various changes or whether they're still needed.

strikebot/src/strikebot/__init__.py
strikebot/src/strikebot/__main__.py
strikebot/src/strikebot/db.py
strikebot/src/strikebot/live_ws.py
strikebot/src/strikebot/queue.py

index 7c37d140408f1f419a2cee25b04d8ab9ccf3cca8..4c7c49611934f8c62abf4631ce7deb9a009356cf 100644 (file)
@@ -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_)
index 4c2b1d906f9c0066fe2d2e9a683abbb8e5f91475..ac490b6f901e10cfe6e063a604064473a53be486 100644 (file)
@@ -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
 
index c9a060af8dc5c229d168f6193cbcfc5a2cd78698..d1a2f42421b463a7858eda6447f4f93592fb98c2 100644 (file)
@@ -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
index cb8b3d0b63f26cd168c310e2e3cd8847b479e179..031d65217a68415e65ec2d7657a08416145e5fb5 100644 (file)
@@ -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()
index adfbbe64013e0884ca9f8b2624c9cdf87abf9c8e..acf5ef00cef06a45bbfe01815d37877d16e60143 100644 (file)
@@ -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: