-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: respect wait for clear_output #969
Merged
MSeal
merged 3 commits into
jupyter:master
from
maartenbreddels:fix_clear_output_with_wait
Mar 21, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -440,6 +440,7 @@ def run_cell(self, cell, cell_index=0): | |
exec_reply = self._wait_for_reply(msg_id, cell) | ||
|
||
outs = cell.outputs = [] | ||
self.clear_before_next_output = False | ||
|
||
while True: | ||
try: | ||
|
@@ -475,13 +476,10 @@ def run_cell(self, cell, cell_index=0): | |
elif msg_type == 'execute_input': | ||
continue | ||
elif msg_type == 'clear_output': | ||
outs[:] = [] | ||
# clear display_id mapping for this cell | ||
for display_id, cell_map in self._display_id_map.items(): | ||
if cell_index in cell_map: | ||
cell_map[cell_index] = [] | ||
self.clear_output(outs, msg, cell_index) | ||
continue | ||
elif msg_type.startswith('comm'): | ||
self.handle_comm_msg(outs, msg, cell_index) | ||
continue | ||
|
||
display_id = None | ||
|
@@ -493,22 +491,48 @@ def run_cell(self, cell, cell_index=0): | |
# update_display_data doesn't get recorded | ||
continue | ||
|
||
try: | ||
out = output_from_msg(msg) | ||
except ValueError: | ||
self.log.error("unhandled iopub msg: " + msg_type) | ||
continue | ||
if display_id: | ||
# record output index in: | ||
# _display_id_map[display_id][cell_idx] | ||
cell_map = self._display_id_map.setdefault(display_id, {}) | ||
output_idx_list = cell_map.setdefault(cell_index, []) | ||
output_idx_list.append(len(outs)) | ||
|
||
outs.append(out) | ||
self.output(outs, msg, display_id, cell_index) | ||
|
||
return exec_reply, outs | ||
|
||
def output(self, outs, msg, display_id, cell_index): | ||
msg_type = msg['msg_type'] | ||
if self.clear_before_next_output: | ||
self.log.debug('Executing delayed clear_output') | ||
outs[:] = [] | ||
self.clear_display_id_mapping(cell_index) | ||
self.clear_before_next_output = False | ||
|
||
try: | ||
out = output_from_msg(msg) | ||
except ValueError: | ||
self.log.error("unhandled iopub msg: " + msg_type) | ||
return | ||
if display_id: | ||
# record output index in: | ||
# _display_id_map[display_id][cell_idx] | ||
cell_map = self._display_id_map.setdefault(display_id, {}) | ||
output_idx_list = cell_map.setdefault(cell_index, []) | ||
output_idx_list.append(len(outs)) | ||
outs.append(out) | ||
|
||
def clear_output(self, outs, msg, cell_index): | ||
content = msg['content'] | ||
if content.get('wait'): | ||
self.log.debug('Wait to clear output') | ||
self.clear_before_next_output = True | ||
else: | ||
self.log.debug('Immediate clear output') | ||
outs[:] = [] | ||
self.clear_display_id_mapping(cell_index) | ||
|
||
def clear_display_id_mapping(self, cell_index): | ||
for display_id, cell_map in self._display_id_map.items(): | ||
if cell_index in cell_map: | ||
cell_map[cell_index] = [] | ||
|
||
def handle_comm_msg(self, outs, msg, cell_index): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea for extensions to overwrite :) |
||
pass | ||
|
||
def executenb(nb, cwd=None, km=None, **kwargs): | ||
"""Execute a notebook's code, updating outputs within the notebook object. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check if this is True before exiting (if it were the final message) and clear just before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, if nothing is outputted, it should not clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be covered by the notebook btw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I more meant if the final line of the final cell were
clear_output(wait=True)
wouldn't this not apply clear before exitingrun_cell
? I might be missing a behavioral aspect this morning before my coffee kicks in :DThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would not clear, and it should not. One of the cells in the
notebook has this. Unless you found a scenario I did not test. (apparently, reply by email does not work well with threads).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks, looks good to me them. I'll get to looking at your other PRs related to widgets this next week (been super busy)