diff --git a/IPython/frontend/qt/base_frontend_mixin.py b/IPython/frontend/qt/base_frontend_mixin.py index 3eaa759..b752bfa 100644 --- a/IPython/frontend/qt/base_frontend_mixin.py +++ b/IPython/frontend/qt/base_frontend_mixin.py @@ -73,13 +73,21 @@ class BaseFrontendMixin(object): """ #--------------------------------------------------------------------------- - # Private interface + # 'BaseFrontendMixin' protected interface #--------------------------------------------------------------------------- def _dispatch(self, msg): - """ Call the frontend handler associated with + """ Calls the frontend handler associated with the message type of the + given message. """ msg_type = msg['msg_type'] handler = getattr(self, '_handle_' + msg_type, None) if handler: handler(msg) + + def _is_from_this_session(self, msg): + """ Returns whether a reply from the kernel originated from a request + from this frontend. + """ + session = self._kernel_manager.session.session + return msg['parent_header']['session'] == session diff --git a/IPython/frontend/qt/console/frontend_widget.py b/IPython/frontend/qt/console/frontend_widget.py index 4b42a05..7afb714 100644 --- a/IPython/frontend/qt/console/frontend_widget.py +++ b/IPython/frontend/qt/console/frontend_widget.py @@ -83,7 +83,7 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): # FrontendWidget protected variables. self._call_tip_widget = CallTipWidget(self._control) self._completion_lexer = CompletionLexer(PythonLexer()) - self._hidden = True + self._hidden = False self._highlighter = self._highlighter_class(self) self._input_splitter = self._input_splitter_class(input_mode='replace') self._kernel_manager = None @@ -187,7 +187,6 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): elif status == 'abort': self._process_execute_abort(msg) - self._hidden = True self._show_interpreter_prompt_for_reply(msg) self.executed.emit(msg) @@ -218,13 +217,15 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): def _handle_pyout(self, msg): """ Handle display hook output. """ - self._append_plain_text(msg['content']['data'] + '\n') + if not self._hidden and self._is_from_this_session(msg): + self._append_plain_text(msg['content']['data'] + '\n') def _handle_stream(self, msg): """ Handle stdout, stderr, and stdin. """ - self._append_plain_text(msg['content']['data']) - self._control.moveCursor(QtGui.QTextCursor.End) + if not self._hidden and self._is_from_this_session(msg): + self._append_plain_text(msg['content']['data']) + self._control.moveCursor(QtGui.QTextCursor.End) def _started_channels(self): """ Called when the KernelManager channels have started listening or diff --git a/IPython/frontend/qt/console/ipython_widget.py b/IPython/frontend/qt/console/ipython_widget.py index 71d2cc5..19ead6d 100644 --- a/IPython/frontend/qt/console/ipython_widget.py +++ b/IPython/frontend/qt/console/ipython_widget.py @@ -75,11 +75,13 @@ class IPythonWidget(FrontendWidget): def _handle_pyout(self, msg): """ Reimplemented for IPython-style "display hook". """ - content = msg['content'] - prompt_number = content['prompt_number'] - self._append_plain_text(content['output_sep']) - self._append_html(self._make_out_prompt(prompt_number)) - self._append_plain_text(content['data'] + '\n' + content['output_sep2']) + if not self._hidden and self._is_from_this_session(msg): + content = msg['content'] + prompt_number = content['prompt_number'] + self._append_plain_text(content['output_sep']) + self._append_html(self._make_out_prompt(prompt_number)) + self._append_plain_text(content['data'] + '\n' + + content['output_sep2']) #--------------------------------------------------------------------------- # 'FrontendWidget' interface diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py index 7959124..9ed616f 100755 --- a/IPython/zmq/ipkernel.py +++ b/IPython/zmq/ipkernel.py @@ -152,8 +152,10 @@ class Kernel(Configurable): raw_input = lambda prompt='': self._raw_input(prompt, ident, parent) __builtin__.raw_input = raw_input - # Set the parent message of the display hook. + # Set the parent message of the display hook and out streams. self.shell.displayhook.set_parent(parent) + sys.stdout.set_parent(parent) + sys.stderr.set_parent(parent) self.shell.runlines(code) except: diff --git a/IPython/zmq/pykernel.py b/IPython/zmq/pykernel.py index 7118a06..fc48861 100755 --- a/IPython/zmq/pykernel.py +++ b/IPython/zmq/pykernel.py @@ -97,8 +97,10 @@ class Kernel(HasTraits): raw_input = lambda prompt='': self._raw_input(prompt, ident, parent) __builtin__.raw_input = raw_input - # Configure the display hook. + # Set the parent message of the display hook and out streams. sys.displayhook.set_parent(parent) + sys.stdout.set_parent(parent) + sys.stderr.set_parent(parent) exec comp_code in self.user_ns, self.user_ns except: