Skip to content
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

Set the default SIGPIPE handler before starting bash. #135

Merged
merged 1 commit into from
Sep 21, 2023

Conversation

sandor-juhasz
Copy link
Contributor

A couple of standard unix tools like head will close the stdin once finished without reading the full contents of the input. This enables idiomatic processing of infinite files like /dev/urandom.

Currently the bash_kernel hangs infinitely or reports broken pipe errors while executing such code.

To reproduce the issue, execute

  • cat /dev/urandom | tr -dc '[:alpha:]' | fold -w ${1:-20} | head -n 1 This will print the output but will hang infinitely.
  • tr -dc '[:alpha:]' </dev/urandom | head -c 10 This will print the output with additional broken pipe error messages.

Root cause of the issue is that Python uses its own signal hander for SIGPIPE to let detecting broken pipes with Python exceptions.

Fix: While temporarily switching to the default SIGINT handler, let's switch to the default SIGPIPE handler too.

@kdm9
Copy link
Collaborator

kdm9 commented Jul 24, 2023

brilliant, thanks for this @sandor-juhasz. Looks good to me but will test it in the coming days. I'll post back with any questions/comments, and then merge it after a week or so in case @takluyver has any comments.

@kdm9 kdm9 merged commit 4a47b36 into takluyver:master Sep 21, 2023
@kdm9 kdm9 mentioned this pull request May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants