Merge pull request #4 from blink1073/add-restart

Restart bash if there are any errors
main
Thomas Kluyver 11 years ago
commit c585990f96

@ -1,6 +1,5 @@
from IPython.kernel.zmq.kernelbase import Kernel from IPython.kernel.zmq.kernelbase import Kernel
from pexpect import replwrap from pexpect import replwrap, EOF
import pexpect
import signal import signal
from subprocess import check_output from subprocess import check_output
@ -28,6 +27,9 @@ class BashKernel(Kernel):
def __init__(self, **kwargs): def __init__(self, **kwargs):
Kernel.__init__(self, **kwargs) Kernel.__init__(self, **kwargs)
self._start_bash()
def _start_bash(self):
# Signal handlers are inherited by forked processes, and we can't easily # Signal handlers are inherited by forked processes, and we can't easily
# reset it from the subprocess. Since kernelapp ignores SIGINT except in # reset it from the subprocess. Since kernelapp ignores SIGINT except in
# message handlers, we need to temporarily reset the SIGINT handler here # message handlers, we need to temporarily reset the SIGINT handler here
@ -52,9 +54,9 @@ class BashKernel(Kernel):
interrupted = True interrupted = True
self.bashwrapper._expect_prompt() self.bashwrapper._expect_prompt()
output = self.bashwrapper.child.before output = self.bashwrapper.child.before
except pexpect.EOF: except EOF:
# TODO: how do we shut down gracefully here? output = self.bashwrapper.child.before + 'Restarting Bash'
output = '' self._start_bash()
if not silent: if not silent:
stream_content = {'name': 'stdout', 'data': output} stream_content = {'name': 'stdout', 'data': output}

Loading…
Cancel
Save