Fix handling of exitcode, name of "payload" key, add stub for shutdown.

main
Steven Silvester 11 years ago
parent 11db1d7d81
commit fe6de313e7

@ -1,5 +1,6 @@
from IPython.kernel.zmq.kernelbase import Kernel from IPython.kernel.zmq.kernelbase import Kernel
from pexpect import replwrap from pexpect import replwrap
import pexpect
import signal import signal
from subprocess import check_output from subprocess import check_output
@ -41,7 +42,7 @@ class BashKernel(Kernel):
allow_stdin=False): allow_stdin=False):
if not code.strip(): if not code.strip():
return {'status': 'ok', 'execution_count': self.execution_count, return {'status': 'ok', 'execution_count': self.execution_count,
'payloads': [], 'user_expressions': {}} 'payload': [], 'user_expressions': {}}
interrupted = False interrupted = False
try: try:
@ -51,16 +52,19 @@ 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:
# TODO: how do we shut down gracefully here?
output = ''
if not silent: if not silent:
stream_content = {'name': 'stdout', 'data':output} stream_content = {'name': 'stdout', 'data': output}
self.send_response(self.iopub_socket, 'stream', stream_content) self.send_response(self.iopub_socket, 'stream', stream_content)
if interrupted: if interrupted:
return {'status': 'abort', 'execution_count': self.execution_count} return {'status': 'abort', 'execution_count': self.execution_count}
try: try:
exitcode = int(self.run_command('echo $?').rstrip()) exitcode = int(self.bashwrapper.run_command('echo $?').rstrip())
except Exception: except Exception:
exitcode = 1 exitcode = 1
@ -69,7 +73,7 @@ class BashKernel(Kernel):
'ename': '', 'evalue': str(exitcode), 'traceback': []} 'ename': '', 'evalue': str(exitcode), 'traceback': []}
else: else:
return {'status': 'ok', 'execution_count': self.execution_count, return {'status': 'ok', 'execution_count': self.execution_count,
'payloads': [], 'user_expressions': {}} 'payload': [], 'user_expressions': {}}
if __name__ == '__main__': if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp from IPython.kernel.zmq.kernelapp import IPKernelApp

Loading…
Cancel
Save