-
-
Notifications
You must be signed in to change notification settings - Fork 32k
logging.StreamHandler produces BrokenPipeError when cut short by head utility #134568
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
Comments
I'm not sure the approach suggested in the
I suggest opening a discussion on |
I just want to reiterate these two points. The linked PR is too specific to a certain use-case. |
Note that this error is not produced by Lines 1803 to 1835 in 3c05251
The following script, which contains no calls to logging: # test2.py
import sys
print('foo')
sys.stdout.flush()
print('bar')
sys.stdout.flush() results in this: $ python3 test2.py | head -1
foo
Traceback (most recent call last):
File "/disk2/vinay/projects/scratch/logging/134568/test2.py", line 5, in <module>
sys.stdout.flush()
~~~~~~~~~~~~~~~~^^
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored on flushing sys.stdout:
BrokenPipeError: [Errno 32] Broken pipe And quite frankly, any code in an application might flush |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
The following code:
when piped to
head -n1
, produces:This is because
logging.StreamHandler.emit
does not handleBrokenPipeError
when flushing the stream.I will fix this with the approach recommended by Note on SIGPIPE.
CPython versions tested on:
CPython main branch, 3.13
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: