-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Enhance %notebook to save outputs, including MIME types and exceptions
#14780
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
Changes from 3 commits
49d14a0
479eba0
787d4bd
786812a
db746f2
fe26455
de1a604
e90fd4c
436dad9
f1b962a
55c5ad1
c97055f
9978579
da863e1
73c2343
b0a2459
a29eefb
0587325
eb6a602
71862af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3200,6 +3200,11 @@ async def run_cell_async( | |||||||||||||||
|
|
||||||||||||||||
| def error_before_exec(value): | ||||||||||||||||
| if store_history: | ||||||||||||||||
| if self.history_manager: | ||||||||||||||||
| # Store formatted traceback and error details | ||||||||||||||||
| self.history_manager.exceptions[self.execution_count] = ( | ||||||||||||||||
| self.format_exception_for_storage(value) | ||||||||||||||||
| ) | ||||||||||||||||
| self.execution_count += 1 | ||||||||||||||||
| result.error_before_exec = value | ||||||||||||||||
| self.last_execution_succeeded = False | ||||||||||||||||
|
|
@@ -3309,12 +3314,54 @@ def error_before_exec(value): | |||||||||||||||
| assert self.history_manager is not None | ||||||||||||||||
| # Write output to the database. Does nothing unless | ||||||||||||||||
| # history output logging is enabled. | ||||||||||||||||
| self.history_manager.store_output(self.execution_count) | ||||||||||||||||
| hm = self.history_manager | ||||||||||||||||
| hm.store_output(self.execution_count) | ||||||||||||||||
| exec_count = self.execution_count | ||||||||||||||||
|
|
||||||||||||||||
| if result.result: | ||||||||||||||||
Darshan808 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||
| # Format the result into a MIME bundle | ||||||||||||||||
| try: | ||||||||||||||||
| mime_obj = ( | ||||||||||||||||
| result.result[0] | ||||||||||||||||
| if isinstance(result.result, list) | ||||||||||||||||
| else result.result | ||||||||||||||||
| ) | ||||||||||||||||
|
||||||||||||||||
| for mime, handler in handlers.items(): | |
| if mime in data: | |
| handler(data[mime], metadata.get(mime, None)) | |
| return | |
| if "text/plain" in data: | |
| print(data["text/plain"]) |
I am not yet 100% sure if this is the best place, but seems fine for first iteration.
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'm facing a slight issue while capturing mime_bundles here.
When only display is called, the MIME output is shown before execution_count is updated. However, when both an output and display are present, the output appears first, then execution_count is updated, and only after that is the MIME output displayed.
How can we determine whether the MIME bundle should be associated with the current or previous execution_count in such cases?
In the screenshot below, in both cases <Figure size ...> and 1, self.shell.execution_count is 5.



Uh oh!
There was an error while loading. Please reload this page.