From 991071f78453d5d221e459529b6cef644e78ed78 2014-02-11 02:16:22 From: Fernando Perez Date: 2014-02-11 02:16:22 Subject: [PATCH] Merge pull request #5077 from minrk/qt-hmm Flush replies when entering an eventloop. This avoids possible hangs when the GUI eventloop prevents queued replies from being sent. Closes #4997. --- diff --git a/IPython/kernel/zmq/eventloops.py b/IPython/kernel/zmq/eventloops.py index 9767c41..3e195a3 100644 --- a/IPython/kernel/zmq/eventloops.py +++ b/IPython/kernel/zmq/eventloops.py @@ -251,5 +251,5 @@ def enable_gui(gui, kernel=None): ) loop = loop_map[gui] if loop and kernel.eventloop is not None and kernel.eventloop is not loop: - raise RuntimeError("Cannot activate multiple GUI eventloops") + raise RuntimeError("Cannot activate multiple GUI eventloops") kernel.eventloop = loop diff --git a/IPython/kernel/zmq/ipkernel.py b/IPython/kernel/zmq/ipkernel.py index 8fc4063..8bfbb05 100755 --- a/IPython/kernel/zmq/ipkernel.py +++ b/IPython/kernel/zmq/ipkernel.py @@ -60,7 +60,7 @@ class Kernel(Configurable): def _eventloop_changed(self, name, old, new): """schedule call to eventloop from IOLoop""" loop = ioloop.IOLoop.instance() - loop.add_timeout(time.time()+0.1, self.enter_eventloop) + loop.add_callback(self.enter_eventloop) shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') shell_class = Type(ZMQInteractiveShell) @@ -250,7 +250,11 @@ class Kernel(Configurable): def enter_eventloop(self): """enter eventloop""" - self.log.info("entering eventloop") + self.log.info("entering eventloop %s", self.eventloop) + for stream in self.shell_streams: + # flush any pending replies, + # which may be skipped by entering the eventloop + stream.flush(zmq.POLLOUT) # restore default_int_handler signal(SIGINT, default_int_handler) while self.eventloop is not None: