summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/streams.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2019-05-14 16:09:44 (GMT)
committerVictor Stinner <vstinner@redhat.com>2019-05-14 16:09:44 (GMT)
commitf12ba7cd0a7370631214ac0b337ab5455ce717b2 (patch)
tree26b7914a776c311c65cb94cd12ffe409eb4f20a8 /Lib/asyncio/streams.py
parentc96be811fa7da8ddcea18cc7abcae94e0f5ff966 (diff)
downloadcpython-f12ba7cd0a7370631214ac0b337ab5455ce717b2.zip
cpython-f12ba7cd0a7370631214ac0b337ab5455ce717b2.tar.gz
cpython-f12ba7cd0a7370631214ac0b337ab5455ce717b2.tar.bz2
bpo-36916: asyncio: Swallow unhandled write() exception (GH-13313)
Diffstat (limited to 'Lib/asyncio/streams.py')
-rw-r--r--Lib/asyncio/streams.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py
index d9a9f5e..146a338 100644
--- a/Lib/asyncio/streams.py
+++ b/Lib/asyncio/streams.py
@@ -329,6 +329,13 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
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.
@@ -393,7 +400,9 @@ class StreamWriter:
# 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()