Skip to content

Commit

Permalink
Merge pull request ipython#1541 from minrk/display_pub_flush
Browse files Browse the repository at this point in the history
display_pub flushes stdout/err

This helps preserve ordering of print statements and display_pub output.

closes ipython#1539
  • Loading branch information
minrk committed Apr 4, 2012
2 parents 94ae6b1 + 121d08d commit ef97b94
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions IPython/zmq/zmqshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ class ZMQDisplayPublisher(DisplayPublisher):
def set_parent(self, parent):
"""Set the parent for outbound messages."""
self.parent_header = extract_header(parent)

def _flush_streams(self):
"""flush IO Streams prior to display"""
sys.stdout.flush()
sys.stderr.flush()

def publish(self, source, data, metadata=None):
self._flush_streams()
if metadata is None:
metadata = {}
self._validate_data(source, data, metadata)
Expand All @@ -75,6 +81,7 @@ def publish(self, source, data, metadata=None):
)

def clear_output(self, stdout=True, stderr=True, other=True):
self._flush_streams()
content = dict(stdout=stdout, stderr=stderr, other=other)
self.session.send(
self.pub_socket, u'clear_output', content,
Expand Down

0 comments on commit ef97b94

Please sign in to comment.