Skip to content

gh-134568: added handler for BrokenPipeError to logging.StreamHandler.emit #134569

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

blhsing
Copy link
Contributor

@blhsing blhsing commented May 23, 2025

@@ -1155,6 +1155,10 @@ def emit(self, record):
self.flush()
except RecursionError: # See issue 36272
raise
except BrokenPipeError:
Copy link
Member

@picnixz picnixz May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a "See issue XXXX" as above for the RecursionError maybe. However, shouldn't we give the possibility to handle the error? maybe BrokenPipeError is coming from somewhere else? Here, you're redirecting sys.stdout but what if it's because of self.stream? (I don't know which is why I ask)

except BrokenPipeError:
devnull = os.open(os.devnull, os.O_WRONLY)
os.dup2(devnull, sys.stdout.fileno())
sys.exit(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, why are we exiting the process?

@@ -1155,6 +1155,10 @@ def emit(self, record):
self.flush()
except RecursionError: # See issue 36272
raise
except BrokenPipeError:
devnull = os.open(os.devnull, os.O_WRONLY)
os.dup2(devnull, sys.stdout.fileno())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this have weird side-effects? Any future stdout writes won't show up.

@vsajip
Copy link
Member

vsajip commented May 24, 2025

See also my comments on the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants