From ad627728af159de885f574a7bd7ab822bdfc4468 2013-02-04 18:10:09 From: MinRK Date: 2013-02-04 18:10:09 Subject: [PATCH] flush on newline in subprocesses reduces issues with mp.Pool --- diff --git a/IPython/kernel/zmq/iostream.py b/IPython/kernel/zmq/iostream.py index 197472e..d9aa802 100644 --- a/IPython/kernel/zmq/iostream.py +++ b/IPython/kernel/zmq/iostream.py @@ -90,6 +90,7 @@ class OutStream(object): return MASTER else: if not self._have_pipe_out(): + self._flush_buffer() # setup a new out pipe self._setup_pipe_out() return CHILD @@ -174,8 +175,15 @@ class OutStream(object): # Make sure that we're handling unicode if not isinstance(string, unicode): string = string.decode(self.encoding, 'replace') + + is_child = (self._check_mp_mode() == CHILD) self._buffer.write(string) - self._check_mp_mode() + if is_child: + # newlines imply flush in subprocesses + # mp.Pool cannot be trusted to flush promptly (or ever), + # and this helps. + if '\n' in string: + self.flush() # do we want to check subprocess flushes on write? # self._flush_from_subprocesses() current_time = time.time()