Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f12ba7cd
Commit
f12ba7cd
authored
May 14, 2019
by
Andrew Svetlov
Committed by
Victor Stinner
May 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-36916: asyncio: Swallow unhandled write() exception (GH-13313)
parent
c96be811
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
1 deletion
+15
-1
Lib/asyncio/streams.py
Lib/asyncio/streams.py
+10
-1
Lib/test/test_asyncio/test_streams.py
Lib/test/test_asyncio/test_streams.py
+3
-0
Misc/NEWS.d/next/Library/2019-05-14-15-39-34.bpo-36916._GPsTt.rst
...S.d/next/Library/2019-05-14-15-39-34.bpo-36916._GPsTt.rst
+2
-0
No files found.
Lib/asyncio/streams.py
View file @
f12ba7cd
...
...
@@ -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
()
...
...
Lib/test/test_asyncio/test_streams.py
View file @
f12ba7cd
...
...
@@ -851,6 +851,8 @@ os.close(fd)
# 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
():
...
...
@@ -883,6 +885,7 @@ os.close(fd)
# 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
,
...
...
Misc/NEWS.d/next/Library/2019-05-14-15-39-34.bpo-36916._GPsTt.rst
0 → 100644
View file @
f12ba7cd
Remove a message about an unhandled exception in a task when writer.write()
is used without await and writer.drain() fails with an exception.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment