diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py index 0966e7d..ca37c3f 100755 --- a/IPython/zmq/ipkernel.py +++ b/IPython/zmq/ipkernel.py @@ -330,7 +330,7 @@ class Kernel(Configurable): def shutdown_request(self, ident, parent): self.shell.exit_now = True - self._shutdown_message = self.session.msg(u'shutdown_reply', {}, parent) + self._shutdown_message = self.session.msg(u'shutdown_reply', parent['content'], parent) sys.exit(0) #--------------------------------------------------------------------------- @@ -428,6 +428,7 @@ class Kernel(Configurable): # io.rprint("Kernel at_shutdown") # dbg if self._shutdown_message is not None: self.reply_socket.send_json(self._shutdown_message) + self.pub_socket.send_json(self._shutdown_message) io.raw_print(self._shutdown_message) # A very short sleep to give zmq time to flush its message buffers # before Python truly shuts down. diff --git a/IPython/zmq/kernelmanager.py b/IPython/zmq/kernelmanager.py index 3794574..46e70cd 100644 --- a/IPython/zmq/kernelmanager.py +++ b/IPython/zmq/kernelmanager.py @@ -305,7 +305,7 @@ class XReqSocketChannel(ZmqSocketChannel): self._queue_request(msg) return msg['header']['msg_id'] - def shutdown(self): + def shutdown(self, restart=False): """Request an immediate kernel shutdown. Upon receipt of the (empty) reply, client code can safely assume that @@ -318,7 +318,7 @@ class XReqSocketChannel(ZmqSocketChannel): """ # Send quit message to kernel. Once we implement kernel-side setattr, # this should probably be done that way, but for now this will do. - msg = self.session.msg('shutdown_request', {}) + msg = self.session.msg('shutdown_request', {'restart':restart}) self._queue_request(msg) return msg['header']['msg_id'] @@ -743,7 +743,7 @@ class KernelManager(HasTraits): self.rep_address = (LOCALHOST, req) self.hb_address = (LOCALHOST, hb) - def shutdown_kernel(self): + def shutdown_kernel(self, restart=False): """ Attempts to the stop the kernel process cleanly. If the kernel cannot be stopped, it is killed, if possible. """ @@ -759,7 +759,7 @@ class KernelManager(HasTraits): # Don't send any additional kernel kill messages immediately, to give # the kernel a chance to properly execute shutdown actions. Wait for at # most 1s, checking every 0.1s. - self.xreq_channel.shutdown() + self.xreq_channel.shutdown(restart=restart) for i in range(10): if self.is_alive: time.sleep(0.1) @@ -793,7 +793,7 @@ class KernelManager(HasTraits): if now: self.kill_kernel() else: - self.shutdown_kernel() + self.shutdown_kernel(restart=True) self.start_kernel(**self._launch_args) # FIXME: Messages get dropped in Windows due to probable ZMQ bug diff --git a/IPython/zmq/pykernel.py b/IPython/zmq/pykernel.py index 3991a17..4938a2a 100755 --- a/IPython/zmq/pykernel.py +++ b/IPython/zmq/pykernel.py @@ -167,6 +167,8 @@ class Kernel(HasTraits): content = dict(parent['content']) msg = self.session.send(self.reply_socket, 'shutdown_reply', content, parent, ident) + msg = self.session.send(self.pub_socket, 'shutdown_reply', + content, parent, ident) print >> sys.__stdout__, msg time.sleep(0.1) sys.exit(0)