Skip to content

Commit 81b7c81

Browse files
authored
Merge pull request #49 from Zac-HD/remove-queue
Upgrade from deprecated trio.Queue; fix tests; fix docs
2 parents 288abcb + f56c4be commit 81b7c81

10 files changed

Lines changed: 35 additions & 24 deletions

File tree

docs/source/rationale.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ domains rigidly separate.
4141

4242
The core of the "normal" asyncio main loop is the repeated execution of
4343
synchronous code that's submitted to
44-
:meth:`asyncio.AbstractEventLoop.call_soon` or
45-
:meth:`asyncio.AbstractEventLoop.call_later`, or as the callbacks for
46-
:meth:`asyncio.AbstractEventLoop.add_reader` /
47-
:meth:`asyncio.AbstractEventLoop.add_writer`.
44+
:meth:`python:asyncio.loop.call_soon` or
45+
:meth:`python:asyncio.loop.call_later`, or as the callbacks for
46+
:meth:`python:asyncio.loop.add_reader` /
47+
:meth:`python:asyncio.loop.add_writer`.
4848

4949
Everything else within the ``asyncio`` core, esp. Futures, Coroutines, and
5050
``await``'ing them, is just syntactic sugar. There is no concept of a

docs/source/usage.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,13 @@ Cancellations are also propagated whenever possible. This means
522522
Deferred Calls
523523
----------------
524524

525-
:meth:`asyncio.AbstractEventLoop.call_soon` and friends work as usual.
525+
:meth:`python:asyncio.loop.call_soon` and friends work as usual.
526526

527527
----------------
528528
Worker Threads
529529
----------------
530530

531-
:meth:`asyncio.AbstractEventLoop.run_in_executor` works as usual.
531+
:meth:`python:asyncio.loop.run_in_executor` works as usual.
532532

533533
There is one caveat: the executor must be either ``None`` or an instance of
534534
:class:`trio_asyncio.TrioExecutor`. The constructor of this class accepts one
@@ -540,8 +540,8 @@ argument: the number of workers.
540540
File descriptors
541541
------------------
542542

543-
:meth:`asyncio.AbstractEventLoop.add_reader` and
544-
:meth:`asyncio.AbstractEventLoop.add_writer` work as usual, if you really
543+
:meth:`python:asyncio.loop.add_reader` and
544+
:meth:`python:asyncio.loop.add_writer` work as usual, if you really
545545
need them. Behind the scenes, these calls create a Trio task which runs the
546546
callback.
547547

@@ -551,7 +551,7 @@ You might consider converting code using these calls to native Trio tasks.
551551
Signals
552552
---------
553553

554-
:meth:`asyncio.AbstractEventLoop.add_signal_handler` works as usual.
554+
:meth:`python:asyncio.loop.add_signal_handler` works as usual.
555555

556556
------------
557557
Subprocesses

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
]

tests/interop/test_adapter.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@
66
import sniffio
77
from tests import aiotest
88
import sys
9+
import warnings
910
from async_generator import asynccontextmanager
1011
from .. import utils as test_utils
1112

1213

14+
def de_deprecate_converter(func):
15+
def wrapper(proc):
16+
with warnings.catch_warnings():
17+
warnings.simplefilter('ignore', DeprecationWarning)
18+
return func(proc)
19+
20+
return wrapper
21+
22+
1323
class SomeThing:
1424
flag = 0
1525

@@ -31,15 +41,15 @@ async def dly_trio_adapted(self):
3141
self.flag |= 2
3242
return 8
3343

34-
@aio2trio
44+
@de_deprecate_converter(aio2trio)
3545
async def dly_trio_depr(self):
3646
if sys.version_info >= (3, 7):
3747
assert sniffio.current_async_library() == "trio"
3848
await trio.sleep(0.01)
3949
self.flag |= 2
4050
return 8
4151

42-
@trio2aio
52+
@de_deprecate_converter(trio2aio)
4353
async def dly_asyncio_depr(self):
4454
if sys.version_info >= (3, 7):
4555
assert sniffio.current_async_library() == "asyncio"

tests/python/test_selector_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
MOCK_ANY = mock.ANY
3131

3232

33-
class TestBaseSelectorEventLoop(BaseSelectorEventLoop):
33+
class BaseSelectorEventLoopForTest(BaseSelectorEventLoop):
3434
def _make_self_pipe(self):
3535
self._ssock = mock.Mock()
3636
self._csock = mock.Mock()
@@ -58,7 +58,7 @@ def setUp(self):
5858
super().setUp()
5959
self.selector = mock.Mock()
6060
self.selector.select.return_value = []
61-
self.loop = TestBaseSelectorEventLoop(self.selector)
61+
self.loop = BaseSelectorEventLoopForTest(self.selector)
6262
self.set_event_loop(self.loop)
6363

6464
def test_make_socket_transport(self):

tests/python/test_subprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
]
2727

2828

29-
class TestSubprocessTransport(base_subprocess.BaseSubprocessTransport):
29+
class SubprocessTransportForTest(base_subprocess.BaseSubprocessTransport):
3030
def _start(self, *args, **kwargs):
3131
self._proc = mock.Mock()
3232
self._proc.stdin = None
@@ -44,7 +44,7 @@ def create_transport(self, waiter=None):
4444
protocol = mock.Mock()
4545
protocol.connection_made._is_coroutine = False
4646
protocol.process_exited._is_coroutine = False
47-
transport = TestSubprocessTransport(
47+
transport = SubprocessTransportForTest(
4848
self.loop, protocol, ['test'], False, None, None, None, 0, waiter=waiter
4949
)
5050
return (transport, protocol)

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)