Restart bash if we get an EOF error.

Restart bash if there are any errors

Limit catches to pexpect.EOF, print previous output

Catch keyboard interrupts while waiting for bash prompt

Revert try/catch around expect_prompt
main
Steven Silvester 11 years ago
parent f718dea58b
commit 8da70a352a

@ -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