Skip to content

Commit

Permalink
Backport PR #2926: Don't die if stderr/stdout do not support set_pare…
Browse files Browse the repository at this point in the history
…nt() #2925

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.

closes #2925
  • Loading branch information
minrk committed Mar 20, 2013
1 parent d994662 commit f85e1f8
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions IPython/zmq/ipkernel.py
Expand Up @@ -352,8 +352,14 @@ def execute_request(self, stream, ident, parent):
# Set the parent message of the display hook and out streams.
shell.displayhook.set_parent(parent)
shell.display_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 @@ -532,13 +538,19 @@ 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)
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 f85e1f8

Please sign in to comment.