##// END OF EJS Templates
fixup shutdown/exit now that we use IOLoop...
MinRK -
Show More
@@ -161,7 +161,7 b' class Kernel(Configurable):'
161 161 for msg_type in msg_types:
162 162 self.shell_handlers[msg_type] = getattr(self, msg_type)
163 163
164 control_msg_types = [ 'clear_request', 'abort_request' ]
164 control_msg_types = msg_types + [ 'clear_request', 'abort_request' ]
165 165 self.control_handlers = {}
166 166 for msg_type in control_msg_types:
167 167 self.control_handlers[msg_type] = getattr(self, msg_type)
@@ -480,14 +480,17 b' class Kernel(Configurable):'
480 480
481 481 def shutdown_request(self, stream, ident, parent):
482 482 self.shell.exit_now = True
483 content = dict(status='ok')
484 content.update(parent['content'])
485 self.session.send(stream, u'shutdown_reply', content, parent, ident=ident)
486 # same content, but different msg_id for broadcasting on IOPub
483 487 self._shutdown_message = self.session.msg(u'shutdown_reply',
484 parent['content'], parent
488 content, parent
485 489 )
486 # self.session.send(stream, self._shutdown_message, ident=ident)
487 490
488 491 self._at_shutdown()
489 492 # call sys.exit after a short delay
490 ioloop.IOLoop.instance().add_timeout(time.time()+0.05, lambda : sys.exit(0))
493 ioloop.IOLoop.instance().add_timeout(time.time()+0.1, lambda : sys.exit(0))
491 494
492 495 #---------------------------------------------------------------------------
493 496 # Engine methods
@@ -615,6 +618,8 b' class Kernel(Configurable):'
615 618 self._abort_queue(stream)
616 619
617 620 def _abort_queue(self, stream):
621 poller = zmq.Poller()
622 poller.register(stream.socket, zmq.POLLIN)
618 623 while True:
619 624 idents,msg = self.session.recv(stream, zmq.NOBLOCK, content=True)
620 625 if msg is None:
@@ -632,7 +637,7 b' class Kernel(Configurable):'
632 637 self.log.debug("%s", reply_msg)
633 638 # We need to wait a bit for requests to come in. This can probably
634 639 # be set shorter for true asynchronous clients.
635 time.sleep(0.05)
640 poller.poll(50)
636 641
637 642
638 643 def _no_raw_input(self):
@@ -19,8 +19,12 b' from __future__ import print_function'
19 19 import inspect
20 20 import os
21 21 import sys
22 import time
22 23 from subprocess import Popen, PIPE
23 24
25 # System library imports
26 from zmq.eventloop import ioloop
27
24 28 # Our own
25 29 from IPython.core.interactiveshell import (
26 30 InteractiveShell, InteractiveShellABC
@@ -115,6 +119,12 b' class ZMQInteractiveShell(InteractiveShell):'
115 119 def _exiter_default(self):
116 120 return ZMQExitAutocall(self)
117 121
122 def _exit_now_changed(self, name, old, new):
123 """stop eventloop when exit_now fires"""
124 if new:
125 loop = ioloop.IOLoop.instance()
126 loop.add_timeout(time.time()+0.1, loop.stop)
127
118 128 keepkernel_on_exit = None
119 129
120 130 # Over ZeroMQ, GUI control isn't done with PyOS_InputHook as there is no
@@ -154,6 +164,7 b' class ZMQInteractiveShell(InteractiveShell):'
154 164
155 165 def ask_exit(self):
156 166 """Engage the exit actions."""
167 self.exit_now = True
157 168 payload = dict(
158 169 source='IPython.zmq.zmqshell.ZMQInteractiveShell.ask_exit',
159 170 exit=True,
General Comments 0
You need to be logged in to leave comments. Login now