closed.exception()
+def _swallow_unhandled_exception(task):
+ # Do a trick to suppress unhandled exception
+ # if stream.write() was used without await and
+ # stream.drain() was paused and resumed with an exception
+ task.exception()
+
+
class StreamWriter:
"""Wraps a Transport.
# fast path, the stream is not paused
# no need to wait for resume signal
return self._complete_fut
- return self._loop.create_task(self.drain())
+ ret = self._loop.create_task(self.drain())
+ ret.add_done_callback(_swallow_unhandled_exception)
+ return ret
def write_eof(self):
return self._transport.write_eof()
# where it never gives up the event loop but the socket is
# closed on the server side.
+ messages = []
+ self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
q = queue.Queue()
def server():
# Clean up the thread. (Only on success; on failure, it may
# be stuck in accept().)
thread.join()
+ self.assertEqual([], messages)
def test___repr__(self):
stream = asyncio.StreamReader(loop=self.loop,