-
Notifications
You must be signed in to change notification settings - Fork 77
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
ENH/FIX: shell command output options #1138
base: master
Are you sure you want to change the base?
Conversation
This breaks two pydm unit tests that intend to check the |
I thought about this just a little bit more, and fixing the tests is trivial, but maybe this leads into some more broad design questions:
I am looking for insight from the the core PyDM team. I'm happy to implement something here that is more future-thinking than the small change currently in the PR diff, which does fix my team's problem but doesn't consider the above questions. |
So I'm not aware of any users who rely on the If we did want to keep this functionality, I think your proposal of None/PIPE/DEVNULL sounds perfect for it. As you say that is much clearer than the
Only one I can think of is the obvious one of someone out there using it already. But I think I'd be fine erring on the side of just going with what you've done in this PR and if someone out there does still want |
In that case, I'll check back in with slack on Monday to see if there's any response, and if not I'll fix the tests and move on for now. edit: I'll implement the full option redesign if that ends up being the easiest way to fix the test suite anyway |
After ruminating on this over the winter shutdown, I decided that there's a lot of value in clarifying the various options here, so I'll go ahead and make a full stdout/stderr option set. I'm thinking the properties will simply be called The pre-existing pydm default is to store both with The existing tests in the test suite will then use Does this seem reasonable? Or would you prefer I hold off on this and do something differently/not at all? |
Sounds great to me! That is both more functional and clearer than the current option, and handles backwards compatibility fine. And I think |
Remaining work:
|
The tests pass windows now, I think the remaining failure is a conda/mamba networking fluke (edit: the networking issue went away upon re-run). I think this is ready for review. I've updated the PR description with some verbose explanation of the changes. |
Note also that this adds a new enum without considering the other active enum PRs. If this goes in before those, the other PRs will need updating. If those go in first, this PR will need updating to match. |
we found some issues with the new enum stuff, so we can have this patch go first and i'll update enum patch accordingly |
Overview
This PR was created to address a bug, but in the process it grew to become a minor rework of how we parameterize
PyDMShellCommand
widgets.Bug Explainer
In the
PyDMShellCommand
widget, we've been usingsubprocess.PIPE
for thestdout
andstderr
arguments tosubprocess.Popen
when we don't want these streams to show in the caller's terminal.Unfortunately, this creates a problem. If the subprocess generates a certain amount of stdout or stderr, the pipe "fills up" so to speak, and then the subprocess is stuck waiting on being allowed to write more to stdout. The subprocess will then "freeze" until the calling process reads enough of the stdout buffer to allow the subprocess to finish writing data.
I'm not sure if this affects all flavors of subprocesses, but this definitely affects shell commands that open chatty Python processes.
Changes Included
Overall, this PR expands and clarifies our options for stdout and stderr output from subprocesses launched from
PyDMShellCommand
widgets. Previously, we parameterized this via theredirectCommandOutput
property, but this property name has become confusing. This parameter still exists and works similarly to before, but now we can explicitly swap between output modes for both stdout and stderr.The new default,
HIDE
, will usesubprocess.DEVNULL
instead of the previous default that usedsubprocess.PIPE
, which avoids the bug above. The legacy behavior is still accessible via theSTORE
option, but the user will need to be mindful that they don't keep a long-running process with lots of outputs to avoid the issues explained above.shell_command.py
TermOutputMode
enum for the new properties with optionsHIDE
,SHOW
, andSTORE
. This was originally created using the style in MNT: Add support to enums in both in PyQt5 and PySide6 #1145 at the time of this PR but this broke designer for me so I've put it back to theQ_ENUMS
etc. style.stdout
andstderr
properties that can be set to the various options fromTermOutputMode
. These are used to select what we pass in as the stdout and stderr options tosubprocess.Popen
redirectCommandOutput
property to modify thestdout
property for backwards compatibility.redirectCommandOutput
andstdout
on the same widget, logging a warning if they do.test_shell_command.py
UserWarning
from thecommand
->commands
deprecation to expect the user warning or avoid it as appropriate so that the warning doesn't bubble up to the pytest output. (This wasn't necessary but it was annoying me)communicate
with thePopen
instance, setstdout
toSTORE
so that they can continue to do so.