-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-91378: Allow subprocess pass-thru with stdout/stderr capture #32344
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
Conversation
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 MissingOur records indicate the following people have not signed the CLA: 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 You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
@Andrew-Shay This should look familiar... |
fad39ca
to
dd6eebf
Compare
dd6eebf
to
5fe4f54
Compare
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.
A few things:
- You're calling
data.decode()
on the read data, but no codec is specified. This is going to cause problems as there is never a guarantee about what an arbitrary process will actually output. A true "tee" should take the binary data it read and write the same binary data out to the destination. Which means you should usesys.stdout.buffer.write(data)
rather thansys.stdout.write(data.decode())
(same for stderr). - This needs a unittest. Look around
test_subprocess.py
for ideas. Executing a child process that executes a child process to see that the expected output winds up in the right place is entirely within reason. - What happens when
tee
is True but the stdout and/or stderr were notPIPE
? If this would be useless, we should make it an error. - Documentation and docstrings need updating (I usually leave this to last), with a practical example.
I'm not decided on if I like this feature as designed or not yet, but I've seen enough code that could use it to know that the need is real in some form or another (you gave a good practical example). So lets get this into shape and see how it looks before making a final decision if this is the desired API or should be tweaked into a different shape.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
5fe4f54
to
21e26ae
Compare
@gpshead Thanks for the comments.
Done
Took a stab at this, but I'm unfamiliar with the test framework or how to debug the failure... any suggestions are appreciated.
Added a test. Please let me know if you feel it's adequate or not.
Agreed. I'll do this last. |
83d3e31
to
c2f3e95
Compare
Update:
@gpshead Added 2 unit tests. |
7339b78
to
4f5b73b
Compare
I have made the requested changes; please review again |
Thanks for making the requested changes! @gpshead: please review the changes made to this pull request. |
4f5b73b
to
88c4250
Compare
b84889c
to
7247a70
Compare
@gpshead Trying your change with It's nearly identical to the preceding test |
286883b
to
db326c7
Compare
@gpshead I could not get this to work. x86 would run out of memory, and amd64 would never exit (but get killed by a timeout). Can you please refine the suggestion? |
I'll try and take a look this week. |
Thanks. I appreciate all of your efforts. |
Any luck? |
@gpshead Not sure what to do at this point. |
Thanks for the ping. Looking into this is still on my TODO list. |
Should I abandon this? |
no, leave it open. i haven't had time. |
Is it an option to proceed with what we have, and circle back to optimize it for WinNT? |
Any progress? |
db326c7
to
8692044
Compare
8692044
to
74400d4
Compare
74400d4
to
7f1ef61
Compare
Let's not go forward with this PR, see my overall comment on the issue. Thanks for your work on it! The particular implementation in progress being done here isn't the reason why, though it is an example of why this complexity is not great to maintain within the stdlib. |
I won't be contributing again. |
Hi @pprindeville , this idea would be to me very welcome as an independent normal library package/module. I personally remember having needed and implemented such kind of feature, but was using thread(s) to consume and share to other thread(s) (and be able to retain the entire output as well) the subprocess output as it arrives basically. but I wished there would have been such package available, would have me saved of that extra work. I understand your frustration but the invoked reason is really valid actually. Anyway, have a good weekend. |
Allow pass-thru of subprocess output even when capturing to buffers
I maintain some build wrappers that both pass the output (both
stdout
andstderr
) through when being run interactively, but also capture logs into artifacts when being run through a CI/CD pipeline.Being able to call
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, tee=True)
would allow harvesting results asoutput, errors = subprocess.communicate()
as well as permitting the results of the running process to be seen in real-time (somemake
recipes invokedocker
and can take a while to complete... buffering until completion would confuse users as it might appear that the recipe has hung).#91378, formerly:
https://bugs.python.org/issue47222