Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ipykernel/displayhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ def __init__(self, session, pub_socket):
self.pub_socket = pub_socket
self.parent_header = {}

def get_execution_count(self):
"""This method is replaced in kernelapp"""
return 0

def __call__(self, obj):
if obj is None:
return

builtin_mod._ = obj
sys.stdout.flush()
sys.stderr.flush()
self.session.send(self.pub_socket, u'execute_result', {u'data':repr(obj)},
contents = {u'execution_count': self.get_execution_count(),
u'data': {'text/plain': repr(obj)},
u'metadata': {}}
self.session.send(self.pub_socket, u'execute_result', contents,
parent=self.parent_header, ident=self.topic)

def set_parent(self, parent):
Expand Down
6 changes: 5 additions & 1 deletion ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ def init_io(self):
sys.stderr = outstream_factory(self.session, self.iopub_thread, u'stderr')
if self.displayhook_class:
displayhook_factory = import_item(str(self.displayhook_class))
sys.displayhook = displayhook_factory(self.session, self.iopub_socket)
self.displayhook = displayhook_factory(self.session, self.iopub_socket)
sys.displayhook = self.displayhook

self.patch_io()

Expand Down Expand Up @@ -365,6 +366,9 @@ def init_kernel(self):
kernel.record_ports(self.ports)
self.kernel = kernel

# Allow the displayhook to get the execution count
self.displayhook.get_execution_count = lambda: kernel.execution_count

def init_gui_pylab(self):
"""Enable GUI event loop integration, taking pylab into account."""

Expand Down