From Newsgroup: comp.lang.misc
Lawrence D’Oliveiro <
ldo@nz.invalid> writes:
On Thu, 18 Sep 2025 01:14:41 -0400, Alan Bawden wrote:
> ... So in fact you can't get a BrokenPipeError unless SIGPIPE is
> actually being ignored!
ldo@theon:~> python3 -c "print('hi there')" | cat /dev/null
Exception ignored on flushing sys.stdout:
BrokenPipeError: [Errno 32] Broken pipe
Note that my one-line Python program does not include any signal()
call to ignore SIGPIPE, yet BrokenPipeError does get raised (and
reported).
Your program doesn't need to call signal(SIGPIPE, SIG_IGN) because Python
does that for you -- precisely so that BrokenPipeError will work as expected. See <
https://docs.python.org/3.13/library/signal.html#general-rules>.
Also see <
https://docs.python.org/3.13/library/signal.html#note-on-sigpipe>, which says some of the same things I said in my original message. (Although
it suggests that you should _not_ risk doing signal(SIGPIPE, SIG_DFL), as I sometimes do...)
--
Alan Bawden
--- Synchronet 3.21a-Linux NewsLink 1.2