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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bash_kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ def _start_bash(self):
# reset it from the subprocess. Since kernelapp ignores SIGINT except in
# message handlers, we need to temporarily reset the SIGINT handler here
# so that bash and its children are interruptible.
sig = signal.signal(signal.SIGINT, signal.SIG_DFL)
old_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_DFL)
# We need to temporarily reset the default signal handler for SIGPIPE so
# that commands like `head` used in a pipe chain can signal to the data
# producers.
old_sigpipe_handler = signal.signal(signal.SIGPIPE, signal.SIG_DFL)
try:
# Note: the next few lines mirror functionality in the
# bash() function of pexpect/replwrap.py. Look at the
Expand All @@ -131,7 +135,8 @@ def _start_bash(self):
extra_init_cmd="export PAGER=cat",
line_output_callback=self.process_output)
finally:
signal.signal(signal.SIGINT, sig)
signal.signal(signal.SIGINT, old_sigint_handler)
signal.signal(signal.SIGPIPE, old_sigpipe_handler)

# Disable bracketed paste (see <https://github.com/takluyver/bash_kernel/issues/117>)
self.bashwrapper.run_command("bind 'set enable-bracketed-paste off' >/dev/null 2>&1 || true")
Expand Down