diff --git a/docs/source/rationale.rst b/docs/source/rationale.rst index 510d3c7b..7b35d6ba 100644 --- a/docs/source/rationale.rst +++ b/docs/source/rationale.rst @@ -41,10 +41,10 @@ domains rigidly separate. The core of the "normal" asyncio main loop is the repeated execution of synchronous code that's submitted to -:meth:`asyncio.AbstractEventLoop.call_soon` or -:meth:`asyncio.AbstractEventLoop.call_later`, or as the callbacks for -:meth:`asyncio.AbstractEventLoop.add_reader` / -:meth:`asyncio.AbstractEventLoop.add_writer`. +:meth:`python:asyncio.loop.call_soon` or +:meth:`python:asyncio.loop.call_later`, or as the callbacks for +:meth:`python:asyncio.loop.add_reader` / +:meth:`python:asyncio.loop.add_writer`. Everything else within the ``asyncio`` core, esp. Futures, Coroutines, and ``await``'ing them, is just syntactic sugar. There is no concept of a diff --git a/docs/source/usage.rst b/docs/source/usage.rst index ef99991e..0ad0b9fb 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -522,13 +522,13 @@ Cancellations are also propagated whenever possible. This means Deferred Calls ---------------- -:meth:`asyncio.AbstractEventLoop.call_soon` and friends work as usual. +:meth:`python:asyncio.loop.call_soon` and friends work as usual. ---------------- Worker Threads ---------------- -:meth:`asyncio.AbstractEventLoop.run_in_executor` works as usual. +:meth:`python:asyncio.loop.run_in_executor` works as usual. There is one caveat: the executor must be either ``None`` or an instance of :class:`trio_asyncio.TrioExecutor`. The constructor of this class accepts one @@ -540,8 +540,8 @@ argument: the number of workers. File descriptors ------------------ -:meth:`asyncio.AbstractEventLoop.add_reader` and -:meth:`asyncio.AbstractEventLoop.add_writer` work as usual, if you really +:meth:`python:asyncio.loop.add_reader` and +:meth:`python:asyncio.loop.add_writer` work as usual, if you really need them. Behind the scenes, these calls create a Trio task which runs the callback. @@ -551,7 +551,7 @@ You might consider converting code using these calls to native Trio tasks. Signals --------- -:meth:`asyncio.AbstractEventLoop.add_signal_handler` works as usual. +:meth:`python:asyncio.loop.add_signal_handler` works as usual. ------------ Subprocesses diff --git a/newsfragments/49.bugfix.rst b/newsfragments/49.bugfix.rst new file mode 100644 index 00000000..e4881d0e --- /dev/null +++ b/newsfragments/49.bugfix.rst @@ -0,0 +1 @@ +Replace deprecated ``trio.Queue`` with new channels, requiring Trio 0.9 or later. diff --git a/setup.py b/setup.py index a30cd24d..976a230a 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,7 @@ """ install_requires = [ - "trio >= 0.5.0", + "trio >= 0.9.0", "async_generator >= 1.6", "outcome", ] diff --git a/tests/interop/test_adapter.py b/tests/interop/test_adapter.py index b72c9519..6fee0cab 100644 --- a/tests/interop/test_adapter.py +++ b/tests/interop/test_adapter.py @@ -6,10 +6,20 @@ import sniffio from tests import aiotest import sys +import warnings from async_generator import asynccontextmanager from .. import utils as test_utils +def de_deprecate_converter(func): + def wrapper(proc): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', DeprecationWarning) + return func(proc) + + return wrapper + + class SomeThing: flag = 0 @@ -31,7 +41,7 @@ async def dly_trio_adapted(self): self.flag |= 2 return 8 - @aio2trio + @de_deprecate_converter(aio2trio) async def dly_trio_depr(self): if sys.version_info >= (3, 7): assert sniffio.current_async_library() == "trio" @@ -39,7 +49,7 @@ async def dly_trio_depr(self): self.flag |= 2 return 8 - @trio2aio + @de_deprecate_converter(trio2aio) async def dly_asyncio_depr(self): if sys.version_info >= (3, 7): assert sniffio.current_async_library() == "asyncio" diff --git a/tests/python/test_selector_events.py b/tests/python/test_selector_events.py index 0243a7fa..ac9e3c65 100644 --- a/tests/python/test_selector_events.py +++ b/tests/python/test_selector_events.py @@ -30,7 +30,7 @@ MOCK_ANY = mock.ANY -class TestBaseSelectorEventLoop(BaseSelectorEventLoop): +class BaseSelectorEventLoopForTest(BaseSelectorEventLoop): def _make_self_pipe(self): self._ssock = mock.Mock() self._csock = mock.Mock() @@ -58,7 +58,7 @@ def setUp(self): super().setUp() self.selector = mock.Mock() self.selector.select.return_value = [] - self.loop = TestBaseSelectorEventLoop(self.selector) + self.loop = BaseSelectorEventLoopForTest(self.selector) self.set_event_loop(self.loop) def test_make_socket_transport(self): diff --git a/tests/python/test_subprocess.py b/tests/python/test_subprocess.py index ab540c3a..f7c6ba8c 100644 --- a/tests/python/test_subprocess.py +++ b/tests/python/test_subprocess.py @@ -26,7 +26,7 @@ ] -class TestSubprocessTransport(base_subprocess.BaseSubprocessTransport): +class SubprocessTransportForTest(base_subprocess.BaseSubprocessTransport): def _start(self, *args, **kwargs): self._proc = mock.Mock() self._proc.stdin = None @@ -44,7 +44,7 @@ def create_transport(self, waiter=None): protocol = mock.Mock() protocol.connection_made._is_coroutine = False protocol.process_exited._is_coroutine = False - transport = TestSubprocessTransport( + transport = SubprocessTransportForTest( self.loop, protocol, ['test'], False, None, None, None, 0, waiter=waiter ) return (transport, protocol) diff --git a/trio_asyncio/async_.py b/trio_asyncio/async_.py index 91020c9c..6bf15c70 100644 --- a/trio_asyncio/async_.py +++ b/trio_asyncio/async_.py @@ -16,7 +16,7 @@ class TrioEventLoop(BaseTrioEventLoop): def _queue_handle(self, handle): self._check_closed() - self._q.put_nowait(handle) + self._q_send.send_nowait(handle) return handle def default_exception_handler(self, context): diff --git a/trio_asyncio/base.py b/trio_asyncio/base.py index d6b80ca8..3162b893 100644 --- a/trio_asyncio/base.py +++ b/trio_asyncio/base.py @@ -150,7 +150,7 @@ def __init__(self, queue_len=None): queue_len = 10000 # Processing queue - self._q = trio.Queue(queue_len) + self._q_send, self._q_recv = trio.open_memory_channel(queue_len) # which files to close? self._close_files = set() @@ -406,7 +406,7 @@ def call_soon_threadsafe(self, callback, *args, context=None): self._check_callback(callback, 'call_soon_threadsafe') self._check_closed() h = Handle(callback, args, self, context=context, is_sync=True) - self._token.run_sync_soon(self._q.put_nowait, h) + self._token.run_sync_soon(self._q_send.send_nowait, h) # drop all timers @@ -512,7 +512,7 @@ async def synchronize(self): def _handle_sig(self, sig, _): """Helper to safely enqueue a signal handler.""" h = self._signal_handlers[sig] - self._token.run_sync_soon(self._q.put_nowait, h) + self._token.run_sync_soon(self._q_send.send_nowait, h) def add_signal_handler(self, sig, callback, *args): """asyncio's method to add a signal handler. @@ -741,10 +741,10 @@ async def _main_loop_one(self, no_wait=False): if obj is None: if no_wait: - obj = self._q.get_nowait() + obj = self._q_recv.receive_nowait() else: with trio.move_on_after(timeout): - obj = await self._q.get() + obj = await self._q_recv.receive() if obj is None: # Timeout reached. Presumably now a timer is ready, # so restart from the beginning. diff --git a/trio_asyncio/sync.py b/trio_asyncio/sync.py index c75bee19..f8d87d2f 100644 --- a/trio_asyncio/sync.py +++ b/trio_asyncio/sync.py @@ -68,7 +68,7 @@ def _queue_handle(self, handle): def put(self, handle): self._some_deferred -= 1 - self._q.put_nowait(handle) + self._q_send.send_nowait(handle) # If we don't have a token, the main loop is not yet running # thus we can't have a race condition. @@ -81,7 +81,7 @@ def put(self, handle): self._some_deferred += 1 self._token.run_sync_soon(put, self, handle) else: - self._q.put_nowait(handle) + self._q_send.send_nowait(handle) return handle def run_forever(self):