From 8da70a352afb905e4d20d51a318d97ca88624e98 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 31 Jul 2014 21:00:05 -0500 Subject: [PATCH] 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 --- bash_kernel.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bash_kernel.py b/bash_kernel.py index e514b4a..631b1a8 100644 --- a/bash_kernel.py +++ b/bash_kernel.py @@ -1,6 +1,5 @@ from IPython.kernel.zmq.kernelbase import Kernel -from pexpect import replwrap -import pexpect +from pexpect import replwrap, EOF import signal from subprocess import check_output @@ -28,6 +27,9 @@ class BashKernel(Kernel): def __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 # reset it from the subprocess. Since kernelapp ignores SIGINT except in # message handlers, we need to temporarily reset the SIGINT handler here @@ -52,9 +54,9 @@ class BashKernel(Kernel): interrupted = True self.bashwrapper._expect_prompt() output = self.bashwrapper.child.before - except pexpect.EOF: - # TODO: how do we shut down gracefully here? - output = '' + except EOF: + output = self.bashwrapper.child.before + 'Restarting Bash' + self._start_bash() if not silent: stream_content = {'name': 'stdout', 'data': output}