-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-130925: Add close()
method to asyncio.StreamReader
#130929
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
base: main
Are you sure you want to change the base?
Changes from all commits
4e33e3f
9bbd936
708a88a
92fb461
c673bdc
36fe4f4
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 | ||||
---|---|---|---|---|---|---|
|
@@ -35,6 +35,17 @@ | |||||
'data = sys.stdin.buffer.read()', | ||||||
'sys.stdout.buffer.write(data)'))] | ||||||
|
||||||
# Program generating infinite data | ||||||
PROGRAM_YES = [ | ||||||
sys.executable, '-c', """\ | ||||||
import sys | ||||||
while True: | ||||||
try: | ||||||
sys.stdout.buffer.write(b"y\\n") | ||||||
except BrokenPipeError: | ||||||
break | ||||||
"""] | ||||||
|
||||||
|
||||||
def tearDownModule(): | ||||||
asyncio._set_event_loop_policy(None) | ||||||
|
@@ -879,6 +890,23 @@ async def main(): | |||||
|
||||||
self.loop.run_until_complete(main()) | ||||||
|
||||||
def test_subprocess_break_pipe(self): | ||||||
# See https://github.com/python/cpython/issues/130925 | ||||||
async def main(): | ||||||
proc = await asyncio.create_subprocess_exec(*PROGRAM_YES, | ||||||
stdout=asyncio.subprocess.PIPE) | ||||||
try: | ||||||
# just make sure the program has executed correctly | ||||||
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.
Suggested change
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 added that comment so it's clear why those otherwise unnecessary lines of code are there. They aren't conceptually part of the unit test though. I can be more clear. |
||||||
data = await proc.stdout.readline() | ||||||
self.assertEqual(data, b"y\n") | ||||||
finally: | ||||||
# we are testing that the following method exists and | ||||||
# has the intended effect of signaling the sub-process to terminate | ||||||
Comment on lines
+903
to
+904
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.
Suggested change
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. Same as before, the comment is there to make it explicit what the intent of the test is and the code included in the test. |
||||||
proc.stdout.close() | ||||||
await proc.wait() | ||||||
|
||||||
self.loop.run_until_complete(main()) | ||||||
|
||||||
|
||||||
if sys.platform != 'win32': | ||||||
# Unix | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,3 @@ | ||||||||||||
:func:`asyncio.StreamReader.close` now exists so that it's possible to | ||||||||||||
signal to sub-processes executed via :func:`asyncio.create_subprocess_exec` | ||||||||||||
that they may cease generating output and exit cleanly. | ||||||||||||
Comment on lines
+1
to
+3
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.
Suggested change
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 think the "so" was a typo? Otherwise I can change this |
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.
Is there a reason to make this a global var? Maybe we can just define it in test?
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.
No reason other than consistency with
PROGRAM_CAT
andPROGRAM_BLOCKED
. I can make it a local variable.