summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Kluyver2014-07-01 17:47:23 -0700
committerThomas Kluyver2014-07-01 17:47:23 -0700
commitd7f79edb8c167fab983426f5fa8456429741573a (patch)
treefead45886b099fd4fb157672e932c1d25ff05a0a
parentaf97cb014657fc0cd8f332fe725c7409de6f0d65 (diff)
downloadscilab_kernel-d7f79edb8c167fab983426f5fa8456429741573a.tar.gz
scilab_kernel-d7f79edb8c167fab983426f5fa8456429741573a.tar.bz2
scilab_kernel-d7f79edb8c167fab983426f5fa8456429741573a.zip
Make bash subprocess interruptible
Prevent inheriting SIG_IGN Closes gh-1
-rw-r--r--bash_kernel.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/bash_kernel.py b/bash_kernel.py
index 2fde49b..14720ff 100644
--- a/bash_kernel.py
+++ b/bash_kernel.py
@@ -1,5 +1,7 @@
from IPython.kernel.zmq.kernelbase import Kernel
from pexpect import replwrap
+
+import signal
from subprocess import check_output
import re
@@ -25,14 +27,22 @@ class BashKernel(Kernel):
def __init__(self, **kwargs):
Kernel.__init__(self, **kwargs)
- self.bashwrapper = replwrap.bash()
+ # Signal handlers are inherited by forked processes, and we can't easily
+ # 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)
+ try:
+ self.bashwrapper = replwrap.bash()
+ finally:
+ signal.signal(signal.SIGINT, sig)
def do_execute(self, code, silent, store_history=True, user_expressions=None,
allow_stdin=False):
if not code.strip():
return {'status': 'ok', 'execution_count': self.execution_count,
'payloads': [], 'user_expressions': {}}
-
+
interrupted = False
try:
output = self.bashwrapper.run_command(code.rstrip(), timeout=None)