-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make pause/resume_reading idepotent and no-op for closed transports #528
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,14 +346,31 @@ def test_pause_resume_reading(self): | |
for i in range(10): | ||
self.loop._run_once() | ||
self.protocol.data_received.assert_called_with(b'data2') | ||
|
||
# pause_reading is idepotent | ||
tr.pause_reading() | ||
tr.pause_reading() | ||
self.assertTrue(tr._paused) | ||
|
||
tr.resume_reading() | ||
self.assertFalse(tr._paused) | ||
self.loop._run_once() | ||
self.protocol.data_received.assert_called_with(b'data3') | ||
self.loop._run_once() | ||
self.protocol.data_received.assert_called_with(b'data4') | ||
|
||
# resume_reading is idepotent | ||
tr.resume_reading() | ||
tr.resume_reading() | ||
|
||
tr.close() | ||
|
||
# pause/resume reading is no-op on closed transport | ||
tr.pause_reading() | ||
self.assertFalse(tr._paused) | ||
tr._paused = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we need a public There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually prefer methods to properties: see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aiohttp maintains in aiohttp |
||
tr.resume_reading() | ||
self.assertTrue(tr._paused) | ||
|
||
def pause_writing_transport(self, high): | ||
tr = self.socket_transport() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand why you want to remove the exception from
pause_reading
. But rising an error on trying toresume_reading
on a closed transport seems reasonable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
resume_reading
is more important. from my experiencepause_reading
is getting called from protocol, and protocol has access to transport object, butresume_reading
usually happen from higher level, from coroutine side. and coroutine usually doesn't have access to transport or protocol directly, it just writes to some kind of data stream.