Skip to content

Commit 1191238

Browse files
author
Andy Chu
committed
[interactive] Fix handling of Ctrl-C.
Addresses issue #239. - We almost always ignore Ctrl-C in the main shell. - But we restore Python's SIGINT handler for the readline binding, so it raises KeyboardInterrupt. - Child processes use the default signal handling SIG_DFL. This seems to be correct but I encourage testing :)
1 parent 208bfa1 commit 1191238

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

bin/oil.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,9 @@ def ShellMain(lang, argv0, argv, login_shell):
512512
else: # Without readline module
513513
display = comp_ui.MinimalDisplay(comp_ui_state, prompt_state, debug_f)
514514

515-
# NOTE: SIGINT is handled in frontend/reader.py. It interacts with
516-
# readline.
515+
# NOTE: SIGINT is temporarily enabled during readline() by
516+
# frontend/reader.py.
517+
signal.signal(signal.SIGINT, signal.SIG_IGN)
517518

518519
# The shell itself should ignore Ctrl-\.
519520
signal.signal(signal.SIGQUIT, signal.SIG_IGN)

core/process.py

+2
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ def Start(self):
550550
elif pid == 0: # child
551551
# Respond to Ctrl-\ (core dump)
552552
signal.signal(signal.SIGQUIT, signal.SIG_DFL)
553+
# Respond to Ctrl-C
554+
signal.signal(signal.SIGINT, signal.SIG_DFL)
553555

554556
# This doesn't make the child respond to Ctrl-Z? Why not? Is there
555557
# something at the Python level? signalmodule.c has PyOS_AfterFork but

frontend/reader.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def _GetLine(self):
6565
#sys.stderr.write(self.prompt_str)
6666

6767
signal.signal(signal.SIGINT, self.orig_handler) # raise KeyboardInterrupt
68-
6968
try:
7069
line = raw_input(self.prompt_str) + '\n' # newline required
7170
except EOFError:
@@ -83,7 +82,7 @@ def _GetLine(self):
8382
# When we're not waiting for input, ignore Ctrl-C so we don't get
8483
# KeyboardInterrupt in weird places. NOTE: This can't be SIG_IGN,
8584
# because that affects the child process.
86-
signal.signal(signal.SIGINT, _DoNothing)
85+
signal.signal(signal.SIGINT, signal.SIG_IGN)
8786
# TODO: Should we restore the user-registered handler?
8887

8988
# Add the line if it's not EOL, the same as the previous line, and we have

0 commit comments

Comments
 (0)