From d34fb7b45f94925bcc88ea3c26f6b350bbe88f77 2012-05-15 00:26:34 From: MinRK Date: 2012-05-15 00:26:34 Subject: [PATCH] minor fixes to allow kernel to be re-entrant * user_mod doesn't typecheck ModuleType, because it can be a DummyMod * start hearbeat thread in initialize step, not start. * ensure shell.exit_now is False at Kernel.start --- diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py index 02b81c9..084a3e6 100755 --- a/IPython/zmq/ipkernel.py +++ b/IPython/zmq/ipkernel.py @@ -84,7 +84,7 @@ class Kernel(Configurable): stdin_socket = Instance(zmq.Socket) log = Instance(logging.Logger) - user_module = Instance('types.ModuleType') + user_module = Any() def _user_module_changed(self, name, old, new): if self.shell is not None: self.shell.user_module = new @@ -250,6 +250,7 @@ class Kernel(Configurable): def start(self): """register dispatchers for streams""" + self.shell.exit_now = False if self.control_stream: self.control_stream.on_recv(self.dispatch_control, copy=False) @@ -501,7 +502,8 @@ class Kernel(Configurable): self._at_shutdown() # call sys.exit after a short delay - ioloop.IOLoop.instance().add_timeout(time.time()+0.1, lambda : sys.exit(0)) + loop = ioloop.IOLoop.instance() + loop.add_timeout(time.time()+0.1, loop.stop) #--------------------------------------------------------------------------- # Engine methods diff --git a/IPython/zmq/kernelapp.py b/IPython/zmq/kernelapp.py index 50968a0..762401f 100644 --- a/IPython/zmq/kernelapp.py +++ b/IPython/zmq/kernelapp.py @@ -225,6 +225,7 @@ class KernelApp(BaseIPythonApplication): self.heartbeat = Heartbeat(hb_ctx, (self.ip, self.hb_port)) self.hb_port = self.heartbeat.port self.log.debug("Heartbeat REP Channel on port: %i"%self.hb_port) + self.heartbeat.start() # Helper to make it easier to connect to an existing kernel. # set log-level to critical, to make sure it is output @@ -302,7 +303,6 @@ class KernelApp(BaseIPythonApplication): sys.stderr.flush() def start(self): - self.heartbeat.start() if self.poller is not None: self.poller.start() self.kernel.start()