Skip to content
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

gh-83925: make asyncio.subprocess communicate similar to non-asyncio #18650

Merged
merged 4 commits into from Apr 28, 2023

Conversation

marmarek
Copy link
Contributor

@marmarek marmarek commented Feb 24, 2020

subprocess's communicate(None) closes stdin of the child process, after
sending no (extra) data. Make asyncio variant do the same.
This fixes issues with processes that waits for EOF on stdin before
continuing.

https://bugs.python.org/issue39744

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@marmarek

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@marmarek
Copy link
Contributor Author

(CLA just signed, probably state not refreshed yet - will recheck tomorrow)

@marmarek marmarek force-pushed the asyncio-communicate-close branch 2 times, most recently from d23078a to fbb5546 Compare February 25, 2020 00:45
@codecov
Copy link

codecov bot commented Feb 25, 2020

Codecov Report

Merging #18650 into master will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18650      +/-   ##
==========================================
- Coverage   82.12%   82.07%   -0.06%     
==========================================
  Files        1956     1955       -1     
  Lines      589451   584109    -5342     
  Branches    44457    44458       +1     
==========================================
- Hits       484065   479380    -4685     
+ Misses      95737    95102     -635     
+ Partials     9649     9627      -22     
Impacted Files Coverage Δ
Lib/distutils/tests/test_bdist_rpm.py 30.00% <0.00%> (-65.00%) ⬇️
Lib/distutils/command/bdist_rpm.py 7.63% <0.00%> (-56.88%) ⬇️
Modules/_decimal/libmpdec/umodarith.h 80.76% <0.00%> (-19.24%) ⬇️
Lib/test/test_urllib2net.py 76.92% <0.00%> (-13.85%) ⬇️
Lib/test/test_smtpnet.py 78.57% <0.00%> (-7.15%) ⬇️
Lib/ftplib.py 63.85% <0.00%> (-6.06%) ⬇️
Lib/test/test_ftplib.py 87.11% <0.00%> (-4.72%) ⬇️
Tools/scripts/db2pickle.py 17.82% <0.00%> (-3.97%) ⬇️
Tools/scripts/pickle2db.py 16.98% <0.00%> (-3.78%) ⬇️
Lib/test/test_socket.py 71.94% <0.00%> (-3.77%) ⬇️
... and 327 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8af4712...fbb5546. Read the comment docs.

Copy link
Sponsor Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @marmarek, Thanks for the PR. If you wish to move this PR forward, please fix the CI errors. Thanks!

@marmarek
Copy link
Contributor Author

Hi @marmarek, Thanks for the PR. If you wish to move this PR forward, please fix the CI errors. Thanks!

Done

@gvanrossum gvanrossum changed the title bpo-39744: make asyncio.subprocess communicate similar to non-asyncio gh-83925: make asyncio.subprocess communicate similar to non-asyncio Apr 27, 2023
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logic is correct. This requires a test and a small doc update though. Can you take care of those?

@@ -0,0 +1 @@
Make func:``asyncio.subprocess.Process.communicate`` close subprocess's stdin even when called with input=None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Make func:``asyncio.subprocess.Process.communicate`` close subprocess's stdin even when called with input=None
Make :func:`asyncio.subprocess.Process.communicate` close the subprocess's stdin even when called with `input=None`.

Oh, there was also a missing : before func. Look at other uses of this syntax in the Doc tree for comparison.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just changed single quotes to double ones, because the build failed and said I need to use double ones...

@gvanrossum
Copy link
Member

(And by "small doc changes" I didn't mean the NEWS file edit; I would like the docs for .communicate() to clarify this.)

@willingc
Copy link
Sponsor Contributor

@marmarek
Copy link
Contributor Author

It seems the doc already describes the behavior after this patch:

   Interact with process:

   1. send data to *stdin* (if *input* is not ``None``);

And also the list of differences vs subprocess.Popen.communicate() do not mention different handling of input parameter. Should I add a note that wasn't the case in older versions? If so, I guess that should be rather in branch for such older versions, no?

… one

subprocess's communicate(None) closes stdin of the child process, after
sending no (extra) data. Make asyncio variant do the same.
This fixes issues with processes that waits for EOF on stdin before
continuing.
@gvanrossum
Copy link
Member

It seems the doc already describes the behavior after this patch:

   Interact with process:

   1. send data to *stdin* (if *input* is not ``None``);

And also the list of differences vs subprocess.Popen.communicate() do not mention different handling of input parameter. Should I add a note that wasn't the case in older versions? If so, I guess that should be rather in branch for such older versions, no?

For now, let's just add a versionchanged note to the description of communicate(). And we won't backport the fix. We can update the 3.11 (and before) docs in a separate PR.

@gvanrossum
Copy link
Member

Also, please don't force-push, it is confusing for reviewers. When we merge a PR we squash commits anyways.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still to do:

  • Fix the NEWS file
  • Add versionchanged note

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@gvanrossum gvanrossum merged commit 67d140d into python:main Apr 28, 2023
19 of 20 checks passed
@gvanrossum
Copy link
Member

I'm not sure this should be backported to 3.11; people might have existing workarounds for the issue that could be broken. (Can you close stdin twice?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants