Mar-27-2023, 05:17 PM
which exception should be raised if a process being run produces output to a pipe normally connected to read its stdout and/or stderr when no output is expected from that process?
BrokenPipeError
BrokenPipeError.mro() [BrokenPipeError, ConnectionError, OSError, Exception, BaseException, object]
(Mar-27-2023, 05:17 PM)Skaperen Wrote: [ -> ]a pipe normally connected to read its stdout and/or stderr when no output is expected from that process?If no output from that process is expected, why do you connect a pipe to receive output? It looks that you are expecting some output under abnormal circumstances and you want to detect if these special circumstances occur. This is very different from expecting no output. I think you should clarify your intention.
(Mar-28-2023, 01:30 PM)Gribouillis Wrote: [ -> ]the pipe is connected so that it can be determined if the process did produce output. that process also needs to not be interrupted by that situation. that process needs to go on running. when it is finally all done this function (which, in other cases, is expected to return data) will raise an exception as a way to pass error conditions (there are other). if the pipe is not connected, then it will be very difficult to detect if the process did produce any output.(Mar-27-2023, 05:17 PM)Skaperen Wrote: [ -> ]a pipe normally connected to read its stdout and/or stderr when no output is expected from that process?If no output from that process is expected, why do you connect a pipe to receive output? It looks that you are expecting some output under abnormal circumstances and you want to detect if these special circumstances occur. This is very different from expecting no output. I think you should clarify your intention.
(Mar-29-2023, 02:19 AM)Skaperen Wrote: [ -> ]when it is finally all done this function (which, in other cases, is expected to return data) will raise an exception as a way to pass error conditionsI think it is best to create your own custom exception in this case
import subprocess as sp def call_spam(): proc = sp.run(['spam',], check=True, stdout=sp.PIPE, stderr=sp.STDOUT) if proc.stdout: raise SpamProducedOutput(proc.stdout) class SpamProducedOutput(RuntimeError): pass