diff --git a/IPython/kernel/zmq/ipkernel.py b/IPython/kernel/zmq/ipkernel.py index e6d1498..d7f0a95 100755 --- a/IPython/kernel/zmq/ipkernel.py +++ b/IPython/kernel/zmq/ipkernel.py @@ -374,17 +374,7 @@ class Kernel(Configurable): __builtin__.input = input # Set the parent message of the display hook and out streams. - shell.displayhook.set_parent(parent) - shell.display_pub.set_parent(parent) - shell.data_pub.set_parent(parent) - try: - sys.stdout.set_parent(parent) - except AttributeError: - pass - try: - sys.stderr.set_parent(parent) - except AttributeError: - pass + shell.set_parent(parent) # Re-broadcast our input for the benefit of listening clients, and # start computing output @@ -590,17 +580,7 @@ class Kernel(Configurable): # Set the parent message of the display hook and out streams. shell = self.shell - shell.displayhook.set_parent(parent) - shell.display_pub.set_parent(parent) - shell.data_pub.set_parent(parent) - try: - sys.stdout.set_parent(parent) - except AttributeError: - pass - try: - sys.stderr.set_parent(parent) - except AttributeError: - pass + shell.set_parent(parent) # pyin_msg = self.session.msg(u'pyin',{u'code':code}, parent=parent) # self.iopub_socket.send(pyin_msg) diff --git a/IPython/kernel/zmq/zmqshell.py b/IPython/kernel/zmq/zmqshell.py index f7e5624..90ba2ed 100644 --- a/IPython/kernel/zmq/zmqshell.py +++ b/IPython/kernel/zmq/zmqshell.py @@ -587,6 +587,20 @@ class ZMQInteractiveShell(InteractiveShell): ) self.payload_manager.write_payload(payload) + def set_parent(self, parent): + """Set the parent header for associating output with its triggering input""" + self.displayhook.set_parent(parent) + self.display_pub.set_parent(parent) + self.data_pub.set_parent(parent) + try: + sys.stdout.set_parent(parent) + except AttributeError: + pass + try: + sys.stderr.set_parent(parent) + except AttributeError: + pass + #------------------------------------------------------------------------- # Things related to magics #-------------------------------------------------------------------------