Skip to content

Commit 4d5b95e

Browse files
committed
Upgrade from deprecated trio.Queue
1 parent 288abcb commit 4d5b95e

5 files changed

Lines changed: 10 additions & 9 deletions

File tree

newsfragments/49.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace deprecated ``trio.Queue`` with new channels, requiring Trio 0.9 or later.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"""
5454

5555
install_requires = [
56-
"trio >= 0.5.0",
56+
"trio >= 0.9.0",
5757
"async_generator >= 1.6",
5858
"outcome",
5959
]

trio_asyncio/async_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TrioEventLoop(BaseTrioEventLoop):
1616

1717
def _queue_handle(self, handle):
1818
self._check_closed()
19-
self._q.put_nowait(handle)
19+
self._q_send.send_nowait(handle)
2020
return handle
2121

2222
def default_exception_handler(self, context):

trio_asyncio/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def __init__(self, queue_len=None):
150150
queue_len = 10000
151151

152152
# Processing queue
153-
self._q = trio.Queue(queue_len)
153+
self._q_send, self._q_recv = trio.open_memory_channel(queue_len)
154154

155155
# which files to close?
156156
self._close_files = set()
@@ -406,7 +406,7 @@ def call_soon_threadsafe(self, callback, *args, context=None):
406406
self._check_callback(callback, 'call_soon_threadsafe')
407407
self._check_closed()
408408
h = Handle(callback, args, self, context=context, is_sync=True)
409-
self._token.run_sync_soon(self._q.put_nowait, h)
409+
self._token.run_sync_soon(self._q_send.send_nowait, h)
410410

411411
# drop all timers
412412

@@ -512,7 +512,7 @@ async def synchronize(self):
512512
def _handle_sig(self, sig, _):
513513
"""Helper to safely enqueue a signal handler."""
514514
h = self._signal_handlers[sig]
515-
self._token.run_sync_soon(self._q.put_nowait, h)
515+
self._token.run_sync_soon(self._q_send.send_nowait, h)
516516

517517
def add_signal_handler(self, sig, callback, *args):
518518
"""asyncio's method to add a signal handler.
@@ -741,10 +741,10 @@ async def _main_loop_one(self, no_wait=False):
741741

742742
if obj is None:
743743
if no_wait:
744-
obj = self._q.get_nowait()
744+
obj = self._q_recv.receive_nowait()
745745
else:
746746
with trio.move_on_after(timeout):
747-
obj = await self._q.get()
747+
obj = await self._q_recv.receive()
748748
if obj is None:
749749
# Timeout reached. Presumably now a timer is ready,
750750
# so restart from the beginning.

trio_asyncio/sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _queue_handle(self, handle):
6868

6969
def put(self, handle):
7070
self._some_deferred -= 1
71-
self._q.put_nowait(handle)
71+
self._q_send.send_nowait(handle)
7272

7373
# If we don't have a token, the main loop is not yet running
7474
# thus we can't have a race condition.
@@ -81,7 +81,7 @@ def put(self, handle):
8181
self._some_deferred += 1
8282
self._token.run_sync_soon(put, self, handle)
8383
else:
84-
self._q.put_nowait(handle)
84+
self._q_send.send_nowait(handle)
8585
return handle
8686

8787
def run_forever(self):

0 commit comments

Comments
 (0)