Skip to content

Commit

Permalink
Merge pull request ipython#5253 from minrk/console-async
Browse files Browse the repository at this point in the history
display any output from this session in terminal console
  • Loading branch information
minrk committed Mar 7, 2014
2 parents 5deaf94 + aca5afd commit e02d69b
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions IPython/terminal/console/interactiveshell.py
Expand Up @@ -159,6 +159,8 @@ def run_cell(self, cell, store_history=True):
should be set to False.
"""
if (not cell) or cell.isspace():
# pressing enter flushes any pending display
self.handle_iopub()
return

if cell.strip() == 'exit':
Expand All @@ -180,7 +182,6 @@ def run_cell(self, cell, store_history=True):
except Empty:
# display intermediate print statements, etc.
self.handle_iopub(msg_id)
pass

# after all of that is done, wait for the execute reply
while self.client.is_alive():
Expand Down Expand Up @@ -222,26 +223,22 @@ def handle_execute_reply(self, msg_id, timeout=None):
self.execution_count = int(content["execution_count"] + 1)


def handle_iopub(self, msg_id):
""" Method to process subscribe channel's messages
def handle_iopub(self, msg_id=''):
"""Process messages on the IOPub channel
This method consumes and processes messages on the IOPub channel,
such as stdout, stderr, pyout and status.
It only displays output that is caused by the given msg_id
It only displays output that is caused by this session.
"""
while self.client.iopub_channel.msg_ready():
sub_msg = self.client.iopub_channel.get_msg()
msg_type = sub_msg['header']['msg_type']
parent = sub_msg["parent_header"]
if (not parent) or msg_id == parent['msg_id']:

if parent.get("session", self.session_id) == self.session_id:
if msg_type == 'status':
state = self._execution_state = sub_msg["content"]["execution_state"]
# idle messages mean an individual sequence is complete,
# so break out of consumption to allow other things to take over.
if state == 'idle':
break

self._execution_state = sub_msg["content"]["execution_state"]
elif msg_type == 'stream':
if sub_msg["content"]["name"] == "stdout":
print(sub_msg["content"]["data"], file=io.stdout, end="")
Expand Down

0 comments on commit e02d69b

Please sign in to comment.