diff --git a/docs/source/reference-core.rst b/docs/source/reference-core.rst index ba383fccdc..ae6bbedc32 100644 --- a/docs/source/reference-core.rst +++ b/docs/source/reference-core.rst @@ -1544,10 +1544,12 @@ Exceptions and warnings .. autoexception:: WouldBlock -.. autoexception:: ResourceBusyError +.. autoexception:: BusyResourceError .. autoexception:: ClosedResourceError +.. autoexception:: BrokenResourceError + .. autoexception:: RunFinishedError .. autoexception:: TrioInternalError diff --git a/docs/source/reference-hazmat.rst b/docs/source/reference-hazmat.rst index 44ae1730bc..c3156617e1 100644 --- a/docs/source/reference-hazmat.rst +++ b/docs/source/reference-hazmat.rst @@ -134,7 +134,7 @@ All environments provide the following functions: different, and this works on ``SOCKET`` handles or Python socket objects. - :raises trio.ResourceBusyError: + :raises trio.BusyResourceError: if another task is already waiting for the given socket to become readable. @@ -148,7 +148,7 @@ All environments provide the following functions: different, and this works on ``SOCKET`` handles or Python socket objects. - :raises trio.ResourceBusyError: + :raises trio.BusyResourceError: if another task is already waiting for the given socket to become writable. :raises trio.ClosedResourceError: @@ -192,7 +192,7 @@ Unix-like systems provide the following functions: :arg fd: integer file descriptor, or else an object with a ``fileno()`` method - :raises trio.ResourceBusyError: + :raises trio.BusyResourceError: if another task is already waiting for the given fd to become readable. :raises trio.ClosedResourceError: @@ -213,7 +213,7 @@ Unix-like systems provide the following functions: :arg fd: integer file descriptor, or else an object with a ``fileno()`` method - :raises trio.ResourceBusyError: + :raises trio.BusyResourceError: if another task is already waiting for the given fd to become writable. :raises trio.ClosedResourceError: diff --git a/docs/source/reference-io.rst b/docs/source/reference-io.rst index a6f09150e7..178b552e39 100644 --- a/docs/source/reference-io.rst +++ b/docs/source/reference-io.rst @@ -144,10 +144,6 @@ Abstract base classes :members: :show-inheritance: -.. currentmodule:: trio - -.. autoexception:: BrokenStreamError - .. currentmodule:: trio.abc .. autoclass:: trio.abc.Listener diff --git a/docs/source/tutorial.rst b/docs/source/tutorial.rst index e142b2f80c..0de7479447 100644 --- a/docs/source/tutorial.rst +++ b/docs/source/tutorial.rst @@ -987,7 +987,7 @@ to isolate that to making just this one task crash, without taking down the whole program. For example, if the client closes the connection at the wrong moment then it's possible this code will end up calling ``send_all`` on a closed connection and get an -:exc:`BrokenStreamError`; that's unfortunate, and in a more serious +:exc:`BrokenResourceError`; that's unfortunate, and in a more serious program we might want to handle it more explicitly, but it doesn't indicate a problem for any *other* connections. On the other hand, if the exception is something like a :exc:`KeyboardInterrupt`, we *do* diff --git a/trio/__init__.py b/trio/__init__.py index 8372c35920..df1994025a 100644 --- a/trio/__init__.py +++ b/trio/__init__.py @@ -17,9 +17,9 @@ from ._core import ( TrioInternalError, RunFinishedError, WouldBlock, Cancelled, - ResourceBusyError, ClosedResourceError, MultiError, run, open_nursery, + BusyResourceError, ClosedResourceError, MultiError, run, open_nursery, open_cancel_scope, current_effective_deadline, TASK_STATUS_IGNORED, - current_time + current_time, BrokenResourceError ) from ._timeouts import ( @@ -36,9 +36,7 @@ BlockingTrioPortal ) -from ._highlevel_generic import ( - aclose_forcefully, BrokenStreamError, StapledStream -) +from ._highlevel_generic import aclose_forcefully, StapledStream from ._signals import catch_signals, open_signal_receiver @@ -87,6 +85,20 @@ issue=36, instead=ClosedResourceError ), + "BrokenStreamError": + _deprecate.DeprecatedAttribute( + BrokenResourceError, + "0.8.0", + issue=620, + instead=BrokenResourceError + ), + "ResourceBusyError": + _deprecate.DeprecatedAttribute( + BusyResourceError, + "0.8.0", + issue=620, + instead=BusyResourceError + ), } _deprecate.enable_attribute_deprecations(hazmat.__name__) diff --git a/trio/_abc.py b/trio/_abc.py index 0ec724e335..e49062a2f1 100644 --- a/trio/_abc.py +++ b/trio/_abc.py @@ -296,10 +296,10 @@ async def send_all(self, data): data (bytes, bytearray, or memoryview): The data to send. Raises: - trio.ResourceBusyError: if another task is already executing a + trio.BusyResourceError: if another task is already executing a :meth:`send_all`, :meth:`wait_send_all_might_not_block`, or :meth:`HalfCloseableStream.send_eof` on this stream. - trio.BrokenStreamError: if something has gone wrong, and the stream + trio.BrokenResourceError: if something has gone wrong, and the stream is broken. trio.ClosedResourceError: if you previously closed this stream object, or if another task closes this stream object while @@ -329,10 +329,10 @@ async def wait_send_all_might_not_block(self): return. When implementing it, err on the side of returning early. Raises: - trio.ResourceBusyError: if another task is already executing a + trio.BusyResourceError: if another task is already executing a :meth:`send_all`, :meth:`wait_send_all_might_not_block`, or :meth:`HalfCloseableStream.send_eof` on this stream. - trio.BrokenStreamError: if something has gone wrong, and the stream + trio.BrokenResourceError: if something has gone wrong, and the stream is broken. trio.ClosedResourceError: if you previously closed this stream object, or if another task closes this stream object while @@ -406,9 +406,9 @@ async def receive_some(self, max_bytes): bytes or bytearray: The data received. Raises: - trio.ResourceBusyError: if two tasks attempt to call + trio.BusyResourceError: if two tasks attempt to call :meth:`receive_some` on the same stream at the same time. - trio.BrokenStreamError: if something has gone wrong, and the stream + trio.BrokenResourceError: if something has gone wrong, and the stream is broken. trio.ClosedResourceError: if you previously closed this stream object, or if another task closes this stream object while @@ -474,11 +474,11 @@ async def send_eof(self): succeed. Raises: - trio.ResourceBusyError: if another task is already executing a + trio.BusyResourceError: if another task is already executing a :meth:`~SendStream.send_all`, :meth:`~SendStream.wait_send_all_might_not_block`, or :meth:`send_eof` on this stream. - trio.BrokenStreamError: if something has gone wrong, and the stream + trio.BrokenResourceError: if something has gone wrong, and the stream is broken. trio.ClosedResourceError: if you previously closed this stream object, or if another task closes this stream object while @@ -504,7 +504,7 @@ async def accept(self): SOCK_SEQPACKET sockets or similar. Raises: - trio.ResourceBusyError: if two tasks attempt to call + trio.BusyResourceError: if two tasks attempt to call :meth:`accept` on the same listener at the same time. trio.ClosedResourceError: if you previously closed this listener object, or if another task closes this listener object while diff --git a/trio/_core/__init__.py b/trio/_core/__init__.py index 004cbc5857..7853ce896c 100644 --- a/trio/_core/__init__.py +++ b/trio/_core/__init__.py @@ -16,7 +16,7 @@ def _public(fn): from ._exceptions import ( TrioInternalError, RunFinishedError, WouldBlock, Cancelled, - ResourceBusyError, ClosedResourceError + BusyResourceError, ClosedResourceError, BrokenResourceError ) from ._multierror import MultiError diff --git a/trio/_core/_exceptions.py b/trio/_core/_exceptions.py index eea9297b33..d8a23136e1 100644 --- a/trio/_core/_exceptions.py +++ b/trio/_core/_exceptions.py @@ -1,16 +1,5 @@ import attr -# Re-exported -__all__ = [ - "TrioInternalError", - "RunFinishedError", - "WouldBlock", - "Cancelled", - "ResourceBusyError", - "ClosedResourceError", -] - - class TrioInternalError(Exception): """Raised by :func:`run` if we encounter a bug in trio, or (possibly) a misuse of one of the low-level :mod:`trio.hazmat` APIs. @@ -95,12 +84,12 @@ def _init(cls): return cls(_marker=cls.__marker) -class ResourceBusyError(Exception): +class BusyResourceError(Exception): """Raised when a task attempts to use a resource that some other task is already using, and this would lead to bugs and nonsense. For example, if two tasks try to send data through the same socket at the - same time, trio will raise :class:`ResourceBusyError` instead of letting + same time, trio will raise :class:`BusyResourceError` instead of letting the data get scrambled. """ @@ -114,6 +103,21 @@ class ClosedResourceError(Exception): by exiting a context manager. If a problem arises elsewhere – for example, because of a network failure, or because a remote peer closed their end of a connection – then that should be indicated by a different exception - class, like :exc:`BrokenStreamError` or an :exc:`OSError` subclass. + class, like :exc:`BrokenResourceError` or an :exc:`OSError` subclass. + + """ + +class BrokenResourceError(Exception): + """Raised when an attempt to use a resource fails due to external + circumstances. + + For example, you might get this if you try to send data on a stream where + the remote side has already closed the connection. + + You *don't* get this error if *you* closed the resource – in that case you + get :class:`ClosedResourceError`. + + This exception's ``__cause__`` attribute will often contain more + information about the underlying error. """ diff --git a/trio/_core/_io_epoll.py b/trio/_core/_io_epoll.py index 8c4b03649b..45d8b8c5c5 100644 --- a/trio/_core/_io_epoll.py +++ b/trio/_core/_io_epoll.py @@ -104,7 +104,7 @@ async def _epoll_wait(self, fd, attr_name): waiters = self._registered[fd] if getattr(waiters, attr_name) is not None: await _core.checkpoint() - raise _core.ResourceBusyError( + raise _core.BusyResourceError( "another task is already reading / writing this fd" ) setattr(waiters, attr_name, _core.current_task()) diff --git a/trio/_core/_io_kqueue.py b/trio/_core/_io_kqueue.py index 14cf810b58..4c4ac69879 100644 --- a/trio/_core/_io_kqueue.py +++ b/trio/_core/_io_kqueue.py @@ -82,7 +82,7 @@ def current_kqueue(self): def monitor_kevent(self, ident, filter): key = (ident, filter) if key in self._registered: - raise _core.ResourceBusyError( + raise _core.BusyResourceError( "attempt to register multiple listeners for same " "ident/filter pair" ) @@ -98,7 +98,7 @@ async def wait_kevent(self, ident, filter, abort_func): key = (ident, filter) if key in self._registered: await _core.checkpoint() - raise _core.ResourceBusyError( + raise _core.BusyResourceError( "attempt to register multiple listeners for same " "ident/filter pair" ) diff --git a/trio/_core/_io_windows.py b/trio/_core/_io_windows.py index d044b1f0a5..44d298c469 100644 --- a/trio/_core/_io_windows.py +++ b/trio/_core/_io_windows.py @@ -299,7 +299,7 @@ async def wait_overlapped(self, handle, lpOverlapped): if isinstance(lpOverlapped, int): lpOverlapped = ffi.cast("LPOVERLAPPED", lpOverlapped) if lpOverlapped in self._overlapped_waiters: - raise _core.ResourceBusyError( + raise _core.BusyResourceError( "another task is already waiting on that lpOverlapped" ) task = _core.current_task() @@ -340,7 +340,7 @@ async def _wait_socket(self, which, sock): sock = sock.fileno() if sock in self._socket_waiters[which]: await _core.checkpoint() - raise _core.ResourceBusyError( + raise _core.BusyResourceError( "another task is already waiting to {} this socket" .format(which) ) diff --git a/trio/_core/tests/test_io.py b/trio/_core/tests/test_io.py index 76abebc773..797e3500a9 100644 --- a/trio/_core/tests/test_io.py +++ b/trio/_core/tests/test_io.py @@ -157,7 +157,7 @@ async def test_double_read(socketpair, wait_readable): nursery.start_soon(wait_readable, a) await wait_all_tasks_blocked() with assert_checkpoints(): - with pytest.raises(_core.ResourceBusyError): + with pytest.raises(_core.BusyResourceError): await wait_readable(a) nursery.cancel_scope.cancel() @@ -172,7 +172,7 @@ async def test_double_write(socketpair, wait_writable): nursery.start_soon(wait_writable, a) await wait_all_tasks_blocked() with assert_checkpoints(): - with pytest.raises(_core.ResourceBusyError): + with pytest.raises(_core.BusyResourceError): await wait_writable(a) nursery.cancel_scope.cancel() diff --git a/trio/_highlevel_generic.py b/trio/_highlevel_generic.py index bda261f3dc..3a0aa51814 100644 --- a/trio/_highlevel_generic.py +++ b/trio/_highlevel_generic.py @@ -3,12 +3,6 @@ from . import _core from .abc import HalfCloseableStream -__all__ = [ - "aclose_forcefully", - "BrokenStreamError", - "StapledStream", -] - async def aclose_forcefully(resource): """Close an async resource or async generator immediately, without @@ -40,23 +34,6 @@ async def aclose_forcefully(resource): await resource.aclose() -class BrokenStreamError(Exception): - """Raised when an attempt to use a stream fails due to external - circumstances. - - For example, you might get this if you try to send data on a stream where - the remote side has already closed the connection. - - You *don't* get this error if *you* closed the stream – in that case you - get :class:`ClosedResourceError`. - - This exception's ``__cause__`` attribute will often contain more - information about the underlying error. - - """ - pass - - @attr.s(cmp=False, hash=False) class StapledStream(HalfCloseableStream): """This class `staples `__ diff --git a/trio/_highlevel_socket.py b/trio/_highlevel_socket.py index a3c003f95a..62b085b5b4 100644 --- a/trio/_highlevel_socket.py +++ b/trio/_highlevel_socket.py @@ -7,7 +7,6 @@ from . import socket as tsocket from ._util import ConflictDetector from .abc import HalfCloseableStream, Listener -from ._highlevel_generic import BrokenStreamError __all__ = ["SocketStream", "SocketListener"] @@ -29,7 +28,7 @@ def _translate_socket_errors_to_stream_errors(): "this socket was already closed" ) from None else: - raise BrokenStreamError( + raise _core.BrokenResourceError( "socket connection broken: {}".format(exc) ) from exc diff --git a/trio/_ssl.py b/trio/_ssl.py index 75b3d9758d..3681e6200a 100644 --- a/trio/_ssl.py +++ b/trio/_ssl.py @@ -155,7 +155,7 @@ from . import _core from .abc import Stream, Listener -from ._highlevel_generic import BrokenStreamError, aclose_forcefully +from ._highlevel_generic import aclose_forcefully from . import _sync from ._util import ConflictDetector @@ -409,7 +409,7 @@ def _check_status(self): if self._state is _State.OK: return elif self._state is _State.BROKEN: - raise BrokenStreamError + raise _core.BrokenResourceError elif self._state is _State.CLOSED: raise _core.ClosedResourceError else: # pragma: no cover @@ -459,7 +459,7 @@ async def _retry(self, fn, *args, ignore_want_read=False): _stdlib_ssl.SSLError, _stdlib_ssl.CertificateError ) as exc: self._state = _State.BROKEN - raise BrokenStreamError from exc + raise _core.BrokenResourceError from exc else: finished = True if ignore_want_read: @@ -591,7 +591,7 @@ async def do_handshake(self): .. warning:: If this method is cancelled, then it may leave the :class:`SSLStream` in an unusable state. If this happens then any future attempt to use the object will raise - :exc:`trio.BrokenStreamError`. + :exc:`trio.BrokenResourceError`. """ try: @@ -619,14 +619,14 @@ async def receive_some(self, max_bytes): or a renegotiation are in progress, then it may leave the :class:`SSLStream` in an unusable state. If this happens then any future attempt to use the object will raise - :exc:`trio.BrokenStreamError`. + :exc:`trio.BrokenResourceError`. """ async with self._outer_recv_conflict_detector: self._check_status() try: await self._handshook.ensure(checkpoint=False) - except BrokenStreamError as exc: + except _core.BrokenResourceError as exc: # For some reason, EOF before handshake sometimes raises # SSLSyscallError instead of SSLEOFError (e.g. on my linux # laptop, but not on appveyor). Thanks openssl. @@ -644,7 +644,7 @@ async def receive_some(self, max_bytes): raise ValueError("max_bytes must be >= 1") try: return await self._retry(self._ssl_object.read, max_bytes) - except BrokenStreamError as exc: + except _core.BrokenResourceError as exc: # This isn't quite equivalent to just returning b"" in the # first place, because we still end up with self._state set to # BROKEN. But that's actually fine, because after getting an @@ -666,7 +666,7 @@ async def send_all(self, data): .. warning:: If this method is cancelled, then it may leave the :class:`SSLStream` in an unusable state. If this happens then any attempt to use the object will raise - :exc:`trio.BrokenStreamError`. + :exc:`trio.BrokenResourceError`. """ async with self._outer_send_conflict_detector: @@ -759,9 +759,9 @@ async def aclose(self): # Also, because the other side might have already sent # close_notify and closed their connection then it's possible that # our attempt to send close_notify will raise - # BrokenStreamError. This is totally legal, and in fact can happen + # BrokenResourceError. This is totally legal, and in fact can happen # with two well-behaved trio programs talking to each other, so we - # don't want to raise an error. So we suppress BrokenStreamError + # don't want to raise an error. So we suppress BrokenResourceError # here. (This is safe, because literally the only thing this call # to _retry will do is send the close_notify alert, so that's # surely where the error comes from.) @@ -783,7 +783,7 @@ async def aclose(self): await self._retry( self._ssl_object.unwrap, ignore_want_read=True ) - except (BrokenStreamError, _core.ResourceBusyError): + except (_core.BrokenResourceError, _core.BusyResourceError): pass except: # Failure! Kill the stream and move on. diff --git a/trio/_subprocess/unix_pipes.py b/trio/_subprocess/unix_pipes.py index c812e3fcad..7d7c94891e 100644 --- a/trio/_subprocess/unix_pipes.py +++ b/trio/_subprocess/unix_pipes.py @@ -2,7 +2,7 @@ import os from typing import Tuple -from .. import _core, BrokenStreamError +from .. import _core, BrokenResourceError from .._abc import SendStream, ReceiveStream __all__ = ["PipeSendStream", "PipeReceiveStream", "make_pipe"] @@ -65,7 +65,7 @@ async def send_all(self, data: bytes): total_sent += os.write(self._pipe, remaining) except BrokenPipeError as e: await _core.checkpoint() - raise BrokenStreamError from e + raise BrokenResourceError from e except BlockingIOError: await self.wait_send_all_might_not_block() @@ -82,7 +82,7 @@ async def wait_send_all_might_not_block(self) -> None: # also doesn't checkpoint so we have to do that # ourselves here too await _core.checkpoint() - raise BrokenStreamError from e + raise BrokenResourceError from e class PipeReceiveStream(_PipeMixin, ReceiveStream): diff --git a/trio/_util.py b/trio/_util.py index 89784a5c0f..bfe7138191 100644 --- a/trio/_util.py +++ b/trio/_util.py @@ -112,7 +112,7 @@ def __init__(self, msg): def __enter__(self): if self._held: - raise _core.ResourceBusyError(self._msg) + raise _core.BusyResourceError(self._msg) else: self._held = True diff --git a/trio/testing/_check_streams.py b/trio/testing/_check_streams.py index 85bf98cd94..0beb1ef1d8 100644 --- a/trio/testing/_check_streams.py +++ b/trio/testing/_check_streams.py @@ -4,7 +4,7 @@ import random from .. import _core -from .._highlevel_generic import BrokenStreamError, aclose_forcefully +from .._highlevel_generic import aclose_forcefully from .._abc import SendStream, ReceiveStream, Stream, HalfCloseableStream from ._checkpoints import assert_checkpoints @@ -112,7 +112,7 @@ async def send_empty_then_y(): with _assert_raises(TypeError): await r.receive_some(1.5) - with _assert_raises(_core.ResourceBusyError): + with _assert_raises(_core.BusyResourceError): async with _core.open_nursery() as nursery: nursery.start_soon(do_receive_some, 1) nursery.start_soon(do_receive_some, 1) @@ -134,10 +134,10 @@ async def simple_check_wait_send_all_might_not_block(scope): ) nursery.start_soon(do_receive_some, 1) - # closing the r side leads to BrokenStreamError on the s side + # closing the r side leads to BrokenResourceError on the s side # (eventually) async def expect_broken_stream_on_send(): - with _assert_raises(BrokenStreamError): + with _assert_raises(_core.BrokenResourceError): while True: await do_send_all(b"x" * 100) @@ -146,7 +146,7 @@ async def expect_broken_stream_on_send(): nursery.start_soon(do_aclose, r) # once detected, the stream stays broken - with _assert_raises(BrokenStreamError): + with _assert_raises(_core.BrokenResourceError): await do_send_all(b"x" * 100) # r closed -> ClosedResourceError on the receive side @@ -196,7 +196,7 @@ async def receive_send_then_close(): async with _ForceCloseBoth(await stream_maker()) as (s, r): await aclose_forcefully(r) - with _assert_raises(BrokenStreamError): + with _assert_raises(_core.BrokenResourceError): while True: await do_send_all(b"x" * 100) @@ -210,11 +210,11 @@ async def receive_send_then_close(): await do_send_all(b"123") # after the sender does a forceful close, the receiver might either - # get BrokenStreamError or a clean b""; either is OK. Not OK would be + # get BrokenResourceError or a clean b""; either is OK. Not OK would be # if it freezes, or returns data. try: await checked_receive_1(b"") - except BrokenStreamError: + except _core.BrokenResourceError: pass # cancelled aclose still closes @@ -303,7 +303,7 @@ async def receiver(): async with _ForceCloseBoth(await clogged_stream_maker()) as (s, r): # simultaneous wait_send_all_might_not_block fails - with _assert_raises(_core.ResourceBusyError): + with _assert_raises(_core.BusyResourceError): async with _core.open_nursery() as nursery: nursery.start_soon(s.wait_send_all_might_not_block) nursery.start_soon(s.wait_send_all_might_not_block) @@ -312,7 +312,7 @@ async def receiver(): # this test might destroy the stream b/c we end up cancelling # send_all and e.g. SSLStream can't handle that, so we have to # recreate afterwards) - with _assert_raises(_core.ResourceBusyError): + with _assert_raises(_core.BusyResourceError): async with _core.open_nursery() as nursery: nursery.start_soon(s.wait_send_all_might_not_block) nursery.start_soon(s.send_all, b"123") @@ -320,7 +320,7 @@ async def receiver(): async with _ForceCloseBoth(await clogged_stream_maker()) as (s, r): # send_all and send_all blocked simultaneously should also raise # (but again this might destroy the stream) - with _assert_raises(_core.ResourceBusyError): + with _assert_raises(_core.BusyResourceError): async with _core.open_nursery() as nursery: nursery.start_soon(s.send_all, b"123") nursery.start_soon(s.send_all, b"123") @@ -332,7 +332,7 @@ async def sender(): try: with assert_checkpoints(): await s.wait_send_all_might_not_block() - except BrokenStreamError: + except _core.BrokenResourceError: pass async def receiver(): @@ -349,7 +349,7 @@ async def receiver(): try: with assert_checkpoints(): await s.wait_send_all_might_not_block() - except BrokenStreamError: + except _core.BrokenResourceError: pass # Check that if a task is blocked in a send-side method, then closing @@ -492,7 +492,7 @@ async def expect_x_then_eof(r): if clogged_stream_maker is not None: async with _ForceCloseBoth(await clogged_stream_maker()) as (s1, s2): # send_all and send_eof simultaneously is not ok - with _assert_raises(_core.ResourceBusyError): + with _assert_raises(_core.BusyResourceError): async with _core.open_nursery() as nursery: nursery.start_soon(s1.send_all, b"x") await _core.wait_all_tasks_blocked() @@ -501,7 +501,7 @@ async def expect_x_then_eof(r): async with _ForceCloseBoth(await clogged_stream_maker()) as (s1, s2): # wait_send_all_might_not_block and send_eof simultaneously is not # ok either - with _assert_raises(_core.ResourceBusyError): + with _assert_raises(_core.BusyResourceError): async with _core.open_nursery() as nursery: nursery.start_soon(s1.wait_send_all_might_not_block) await _core.wait_all_tasks_blocked() diff --git a/trio/testing/_memory_streams.py b/trio/testing/_memory_streams.py index 27b457ecda..9e080e8e91 100644 --- a/trio/testing/_memory_streams.py +++ b/trio/testing/_memory_streams.py @@ -1,7 +1,7 @@ import operator from .. import _core -from .._highlevel_generic import BrokenStreamError, StapledStream +from .._highlevel_generic import StapledStream from .. import _util from ..abc import SendStream, ReceiveStream @@ -309,7 +309,7 @@ def memory_stream_pump( else: memory_receive_stream.put_data(data) except _core.ClosedResourceError: - raise BrokenStreamError("MemoryReceiveStream was closed") + raise _core.BrokenResourceError("MemoryReceiveStream was closed") return True @@ -484,7 +484,7 @@ async def send_all(self, data): if self._sender_closed: raise _core.ClosedResourceError if self._receiver_closed: - raise BrokenStreamError + raise _core.BrokenResourceError assert not self._data self._data += data self._something_happened() @@ -492,7 +492,7 @@ async def send_all(self, data): if self._sender_closed: raise _core.ClosedResourceError if self._data and self._receiver_closed: - raise BrokenStreamError + raise _core.BrokenResourceError async def wait_send_all_might_not_block(self): async with self._send_conflict_detector: diff --git a/trio/tests/test_highlevel_ssl_helpers.py b/trio/tests/test_highlevel_ssl_helpers.py index a7e367dc38..41cdb2dc25 100644 --- a/trio/tests/test_highlevel_ssl_helpers.py +++ b/trio/tests/test_highlevel_ssl_helpers.py @@ -22,7 +22,7 @@ async def echo_handler(stream): if not data: break await stream.send_all(data) - except trio.BrokenStreamError: + except trio.BrokenResourceError: pass @@ -58,7 +58,7 @@ async def test_open_ssl_over_tcp_stream_and_everything_else(): # We don't have the right trust set up # (checks that ssl_context=None is doing some validation) stream = await open_ssl_over_tcp_stream("trio-test-1.example.org", 80) - with pytest.raises(trio.BrokenStreamError): + with pytest.raises(trio.BrokenResourceError): await stream.do_handshake() # We have the trust but not the hostname @@ -68,7 +68,7 @@ async def test_open_ssl_over_tcp_stream_and_everything_else(): 80, ssl_context=CLIENT_CTX, ) - with pytest.raises(trio.BrokenStreamError): + with pytest.raises(trio.BrokenResourceError): await stream.do_handshake() # This one should work! diff --git a/trio/tests/test_signals.py b/trio/tests/test_signals.py index cf048844e5..d97a1e36d1 100644 --- a/trio/tests/test_signals.py +++ b/trio/tests/test_signals.py @@ -82,7 +82,7 @@ async def naughty(): async def test_open_signal_receiver_conflict(): - with pytest.raises(trio.ResourceBusyError): + with pytest.raises(trio.BusyResourceError): with open_signal_receiver(signal.SIGILL) as receiver: async with trio.open_nursery() as nursery: nursery.start_soon(receiver.__anext__) diff --git a/trio/tests/test_ssl.py b/trio/tests/test_ssl.py index ed0c28d499..d89237a19f 100644 --- a/trio/tests/test_ssl.py +++ b/trio/tests/test_ssl.py @@ -13,8 +13,8 @@ import trio from .. import _core from .._highlevel_socket import SocketStream, SocketListener -from .._highlevel_generic import BrokenStreamError, aclose_forcefully -from .._core import ClosedResourceError +from .._highlevel_generic import aclose_forcefully +from .._core import ClosedResourceError, BrokenResourceError from .._highlevel_open_tcp_stream import open_tcp_stream from .. import ssl as tssl from .. import socket as tsocket @@ -272,28 +272,28 @@ async def test_PyOpenSSLEchoStream_gives_resource_busy_errors(): # PyOpenSSLEchoStream will notice and complain. s = PyOpenSSLEchoStream() - with pytest.raises(_core.ResourceBusyError) as excinfo: + with pytest.raises(_core.BusyResourceError) as excinfo: async with _core.open_nursery() as nursery: nursery.start_soon(s.send_all, b"x") nursery.start_soon(s.send_all, b"x") assert "simultaneous" in str(excinfo.value) s = PyOpenSSLEchoStream() - with pytest.raises(_core.ResourceBusyError) as excinfo: + with pytest.raises(_core.BusyResourceError) as excinfo: async with _core.open_nursery() as nursery: nursery.start_soon(s.send_all, b"x") nursery.start_soon(s.wait_send_all_might_not_block) assert "simultaneous" in str(excinfo.value) s = PyOpenSSLEchoStream() - with pytest.raises(_core.ResourceBusyError) as excinfo: + with pytest.raises(_core.BusyResourceError) as excinfo: async with _core.open_nursery() as nursery: nursery.start_soon(s.wait_send_all_might_not_block) nursery.start_soon(s.wait_send_all_might_not_block) assert "simultaneous" in str(excinfo.value) s = PyOpenSSLEchoStream() - with pytest.raises(_core.ResourceBusyError) as excinfo: + with pytest.raises(_core.BusyResourceError) as excinfo: async with _core.open_nursery() as nursery: nursery.start_soon(s.receive_some, 1) nursery.start_soon(s.receive_some, 1) @@ -363,7 +363,7 @@ async def test_ssl_client_basics(): sock, client_ctx, server_hostname="trio-test-1.example.org" ) assert not s.server_side - with pytest.raises(BrokenStreamError) as excinfo: + with pytest.raises(BrokenResourceError) as excinfo: await s.send_all(b"x") assert isinstance(excinfo.value.__cause__, tssl.SSLError) @@ -373,7 +373,7 @@ async def test_ssl_client_basics(): sock, CLIENT_CTX, server_hostname="trio-test-2.example.org" ) assert not s.server_side - with pytest.raises(BrokenStreamError) as excinfo: + with pytest.raises(BrokenResourceError) as excinfo: await s.send_all(b"x") assert isinstance(excinfo.value.__cause__, tssl.CertificateError) @@ -442,7 +442,7 @@ async def test_attributes(): # fails: s.context = bad_ctx assert s.context is bad_ctx - with pytest.raises(BrokenStreamError) as excinfo: + with pytest.raises(BrokenResourceError) as excinfo: await s.do_handshake() assert isinstance(excinfo.value.__cause__, tssl.SSLError) @@ -664,28 +664,28 @@ async def do_wait_send_all_might_not_block(): await s.wait_send_all_might_not_block() s, _ = ssl_lockstep_stream_pair() - with pytest.raises(_core.ResourceBusyError) as excinfo: + with pytest.raises(_core.BusyResourceError) as excinfo: async with _core.open_nursery() as nursery: nursery.start_soon(do_send_all) nursery.start_soon(do_send_all) assert "another task" in str(excinfo.value) s, _ = ssl_lockstep_stream_pair() - with pytest.raises(_core.ResourceBusyError) as excinfo: + with pytest.raises(_core.BusyResourceError) as excinfo: async with _core.open_nursery() as nursery: nursery.start_soon(do_receive_some) nursery.start_soon(do_receive_some) assert "another task" in str(excinfo.value) s, _ = ssl_lockstep_stream_pair() - with pytest.raises(_core.ResourceBusyError) as excinfo: + with pytest.raises(_core.BusyResourceError) as excinfo: async with _core.open_nursery() as nursery: nursery.start_soon(do_send_all) nursery.start_soon(do_wait_send_all_might_not_block) assert "another task" in str(excinfo.value) s, _ = ssl_lockstep_stream_pair() - with pytest.raises(_core.ResourceBusyError) as excinfo: + with pytest.raises(_core.BusyResourceError) as excinfo: async with _core.open_nursery() as nursery: nursery.start_soon(do_wait_send_all_might_not_block) nursery.start_soon(do_wait_send_all_might_not_block) @@ -909,7 +909,7 @@ async def bad_hook(): with pytest.raises(KeyError): await client.send_all(b"x") - with pytest.raises(BrokenStreamError): + with pytest.raises(BrokenResourceError): await client.wait_send_all_might_not_block() closed = 0 @@ -960,9 +960,9 @@ async def test_ssl_bad_shutdown(): await trio.aclose_forcefully(client) # now the server sees a broken stream - with pytest.raises(BrokenStreamError): + with pytest.raises(BrokenResourceError): await server.receive_some(10) - with pytest.raises(BrokenStreamError): + with pytest.raises(BrokenResourceError): await server.send_all(b"x" * 10) await server.aclose() @@ -981,7 +981,7 @@ async def test_ssl_bad_shutdown_but_its_ok(): await trio.aclose_forcefully(client) # the server sees that as a clean shutdown assert await server.receive_some(10) == b"" - with pytest.raises(BrokenStreamError): + with pytest.raises(BrokenResourceError): await server.send_all(b"x" * 10) await server.aclose() @@ -1004,7 +1004,7 @@ async def test_ssl_handshake_failure_during_aclose(): # simultaneously is allowed. But I guess when https_compatible=False # then it's bad if we can get through a whole connection with a peer # that has no valid certificate, and never raise an error. - with pytest.raises(BrokenStreamError): + with pytest.raises(BrokenResourceError): await s.aclose() @@ -1046,7 +1046,7 @@ async def test_ssl_https_compatibility_disagreement(): # client is in HTTPS-mode, server is not # so client doing graceful_shutdown causes an error on server async def receive_and_expect_error(): - with pytest.raises(BrokenStreamError) as excinfo: + with pytest.raises(BrokenResourceError) as excinfo: await server.receive_some(10) assert isinstance(excinfo.value.__cause__, tssl.SSLEOFError) @@ -1081,7 +1081,7 @@ async def bad_hook(): with assert_checkpoints(): await client.do_handshake() - with pytest.raises(BrokenStreamError): + with pytest.raises(BrokenResourceError): with assert_checkpoints(): await client.do_handshake() @@ -1104,7 +1104,7 @@ async def client_side(cancel_scope): nursery.start_soon(client_side, nursery.cancel_scope) nursery.start_soon(server.do_handshake) - with pytest.raises(BrokenStreamError): + with pytest.raises(BrokenResourceError): with assert_checkpoints(): await client.do_handshake() diff --git a/trio/tests/test_testing.py b/trio/tests/test_testing.py index bdcc6a2fa0..c4fe714b1e 100644 --- a/trio/tests/test_testing.py +++ b/trio/tests/test_testing.py @@ -469,8 +469,8 @@ async def getter(expect): nursery.start_soon(getter, b"xyz") nursery.start_soon(putter, b"xyz") - # Two gets at the same time -> ResourceBusyError - with pytest.raises(_core.ResourceBusyError): + # Two gets at the same time -> BusyResourceError + with pytest.raises(_core.BusyResourceError): async with _core.open_nursery() as nursery: nursery.start_soon(getter, b"asdf") nursery.start_soon(getter, b"asdf") @@ -524,7 +524,7 @@ async def do_send_all(data): with assert_checkpoints(): assert await mss.get_data() == b"456" - # Call send_all twice at once; one should get ResourceBusyError and one + # Call send_all twice at once; one should get BusyResourceError and one # should succeed. But we can't let the error propagate, because it might # cause the other to be cancelled before it can finish doing its thing, # and we don't know which one will get the error. @@ -534,7 +534,7 @@ async def do_send_all_count_resourcebusy(): nonlocal resource_busy_count try: await do_send_all(b"xxx") - except _core.ResourceBusyError: + except _core.BusyResourceError: resource_busy_count += 1 async with _core.open_nursery() as nursery: @@ -606,7 +606,7 @@ async def do_receive_some(max_bytes): with pytest.raises(TypeError): await do_receive_some(None) - with pytest.raises(_core.ResourceBusyError): + with pytest.raises(_core.BusyResourceError): async with _core.open_nursery() as nursery: nursery.start_soon(do_receive_some, 10) nursery.start_soon(do_receive_some, 10) diff --git a/trio/tests/test_util.py b/trio/tests/test_util.py index 84de70fc51..06bf86b66b 100644 --- a/trio/tests/test_util.py +++ b/trio/tests/test_util.py @@ -40,7 +40,7 @@ async def test_ConflictDetector(): async with ul2: print("ok") - with pytest.raises(_core.ResourceBusyError) as excinfo: + with pytest.raises(_core.BusyResourceError) as excinfo: async with ul1: with assert_checkpoints(): async with ul1: @@ -51,14 +51,14 @@ async def wait_with_ul1(): async with ul1: await wait_all_tasks_blocked() - with pytest.raises(_core.ResourceBusyError) as excinfo: + with pytest.raises(_core.BusyResourceError) as excinfo: async with _core.open_nursery() as nursery: nursery.start_soon(wait_with_ul1) nursery.start_soon(wait_with_ul1) assert "ul1" in str(excinfo.value) # mixing sync and async entry - with pytest.raises(_core.ResourceBusyError) as excinfo: + with pytest.raises(_core.BusyResourceError) as excinfo: with ul1.sync: with assert_checkpoints(): async with ul1: