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
58498bc7
Commit
58498bc7
authored
Sep 29, 2019
by
Andrew Svetlov
Committed by
GitHub
Sep 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-38019: correctly handle pause/resume reading of closed asyncio unix pipe (GH-16472)
parent
9a7d9519
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
0 deletions
+39
-0
Lib/asyncio/unix_events.py
Lib/asyncio/unix_events.py
+11
-0
Lib/test/test_asyncio/test_unix_events.py
Lib/test/test_asyncio/test_unix_events.py
+27
-0
Misc/NEWS.d/next/Library/2019-09-29-13-50-24.bpo-38019.6MoOE3.rst
...S.d/next/Library/2019-09-29-13-50-24.bpo-38019.6MoOE3.rst
+1
-0
No files found.
Lib/asyncio/unix_events.py
View file @
58498bc7
...
...
@@ -445,6 +445,7 @@ class _UnixReadPipeTransport(transports.ReadTransport):
self
.
_fileno
=
pipe
.
fileno
()
self
.
_protocol
=
protocol
self
.
_closing
=
False
self
.
_paused
=
False
mode
=
os
.
fstat
(
self
.
_fileno
).
st_mode
if
not
(
stat
.
S_ISFIFO
(
mode
)
or
...
...
@@ -506,10 +507,20 @@ class _UnixReadPipeTransport(transports.ReadTransport):
self
.
_loop
.
call_soon
(
self
.
_call_connection_lost
,
None
)
def
pause_reading
(
self
):
if
self
.
_closing
or
self
.
_paused
:
return
self
.
_paused
=
True
self
.
_loop
.
_remove_reader
(
self
.
_fileno
)
if
self
.
_loop
.
get_debug
():
logger
.
debug
(
"%r pauses reading"
,
self
)
def
resume_reading
(
self
):
if
self
.
_closing
or
not
self
.
_paused
:
return
self
.
_paused
=
False
self
.
_loop
.
_add_reader
(
self
.
_fileno
,
self
.
_read_ready
)
if
self
.
_loop
.
get_debug
():
logger
.
debug
(
"%r resumes reading"
,
self
)
def
set_protocol
(
self
,
protocol
):
self
.
_protocol
=
protocol
...
...
Lib/test/test_asyncio/test_unix_events.py
View file @
58498bc7
...
...
@@ -736,6 +736,7 @@ class UnixReadPipeTransportTests(test_utils.TestCase):
@
mock
.
patch
(
'os.read'
)
def
test_resume_reading
(
self
,
m_read
):
tr
=
self
.
read_pipe_transport
()
tr
.
pause_reading
()
tr
.
resume_reading
()
self
.
loop
.
assert_reader
(
5
,
tr
.
_read_ready
)
...
...
@@ -790,6 +791,32 @@ class UnixReadPipeTransportTests(test_utils.TestCase):
self
.
assertIsNone
(
tr
.
_protocol
)
self
.
assertIsNone
(
tr
.
_loop
)
def
test_pause_reading_on_closed_pipe
(
self
):
tr
=
self
.
read_pipe_transport
()
tr
.
close
()
test_utils
.
run_briefly
(
self
.
loop
)
self
.
assertIsNone
(
tr
.
_loop
)
tr
.
pause_reading
()
def
test_pause_reading_on_paused_pipe
(
self
):
tr
=
self
.
read_pipe_transport
()
tr
.
pause_reading
()
# the second call should do nothing
tr
.
pause_reading
()
def
test_resume_reading_on_closed_pipe
(
self
):
tr
=
self
.
read_pipe_transport
()
tr
.
close
()
test_utils
.
run_briefly
(
self
.
loop
)
self
.
assertIsNone
(
tr
.
_loop
)
tr
.
resume_reading
()
def
test_resume_reading_on_paused_pipe
(
self
):
tr
=
self
.
read_pipe_transport
()
# the pipe is not paused
# resuming should do nothing
tr
.
resume_reading
()
class
UnixWritePipeTransportTests
(
test_utils
.
TestCase
):
...
...
Misc/NEWS.d/next/Library/2019-09-29-13-50-24.bpo-38019.6MoOE3.rst
0 → 100644
View file @
58498bc7
Correctly handle pause/resume reading of closed asyncio unix pipe.
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