Skip to content

Commit

Permalink
Don't die if stderr/stdout do not support set_parent() ipython#2925
Browse files Browse the repository at this point in the history
If the user redirects the streams to a file for example,
the kernel would raise an exception because file
objects do not have set_parent defined, unlike ipython's
OutStream.
This happens even if the user does this in a spawned thread.
  • Loading branch information
y-p committed Feb 12, 2013
1 parent 678a205 commit a88ce70
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions IPython/kernel/zmq/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,14 @@ def execute_request(self, stream, ident, parent):
shell.displayhook.set_parent(parent)
shell.display_pub.set_parent(parent)
shell.data_pub.set_parent(parent)
sys.stdout.set_parent(parent)
sys.stderr.set_parent(parent)
try:
sys.stdout.set_parent(parent)
except AttributeError:
pass
try:
sys.stderr.set_parent(parent)
except AttributeError:
pass

# Re-broadcast our input for the benefit of listening clients, and
# start computing output
Expand Down Expand Up @@ -567,14 +573,20 @@ def apply_request(self, stream, ident, parent):
return

self._publish_status(u'busy', parent)

# 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)
sys.stdout.set_parent(parent)
sys.stderr.set_parent(parent)
try:
sys.stdout.set_parent(parent)
except AttributeError:
pass
try:
sys.stderr.set_parent(parent)
except AttributeError:
pass

# pyin_msg = self.session.msg(u'pyin',{u'code':code}, parent=parent)
# self.iopub_socket.send(pyin_msg)
Expand Down

0 comments on commit a88ce70

Please sign in to comment.