IPython 9.1 enhanced the %notebook magic so that the outputs are now stored too (ipython/ipython#14780). This allows users to spawn an ipython interpreter, a jupyter kernel, or jupyter console and later save their session to an .ipynb file for reference.
However, when using ipykernel (this is jupyter kernel, jupyter console and notebook interfaces) outputs generated via display publisher such as matplotlib plots are lost.
This is because the DisplayPublisher.publish() gets overridden by ipykernel in ZMQDisplayPublisher.publish() without calling the parent method, thus the code which was added in DisplayPublisher.publish():
outputs = self.shell.history_manager.outputs
outputs[self.shell.execution_count].append(
HistoryOutput(output_type="display_data", bundle=data)
)
does not run. The ZMQDisplayPublisher.publish implementation is in:
|
def publish( # type:ignore[override] |
|
self, |
|
data, |
|
metadata=None, |
|
*, |
|
transient=None, |
|
update=False, |
|
**kwargs, |
|
): |
|
"""Publish a display-data message |
I think it would be useful to add this block, but I am not sure if this should be behind a feature flag (to avoid memory duplication for outputs).
Any opinions?
IPython 9.1 enhanced the
%notebookmagic so that the outputs are now stored too (ipython/ipython#14780). This allows users to spawn anipythoninterpreter, ajupyter kernel, orjupyter consoleand later save their session to an.ipynbfile for reference.However, when using
ipykernel(this isjupyter kernel,jupyter consoleand notebook interfaces) outputs generated via display publisher such asmatplotlibplots are lost.This is because the
DisplayPublisher.publish()gets overridden by ipykernel inZMQDisplayPublisher.publish()without calling the parent method, thus the code which was added inDisplayPublisher.publish():does not run. The
ZMQDisplayPublisher.publishimplementation is in:ipykernel/ipykernel/zmqshell.py
Lines 94 to 103 in 39d4c74
I think it would be useful to add this block, but I am not sure if this should be behind a feature flag (to avoid memory duplication for outputs).
Any opinions?