Skip to content

Commit 2f340e2

Browse files
author
Rollo Konig Brock
committed
Issue #12786: Implement hook for Comm messages
1 parent a4cda09 commit 2f340e2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ipykernel/ipkernel.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def _user_ns_changed(self, change):
6262
_sys_raw_input = Any()
6363
_sys_eval_input = Any()
6464

65+
comm_msg_types = [ 'comm_open', 'comm_msg', 'comm_close' ]
66+
6567
def __init__(self, **kwargs):
6668
super(IPythonKernel, self).__init__(**kwargs)
6769

@@ -81,8 +83,7 @@ def __init__(self, **kwargs):
8183
self.comm_manager = CommManager(parent=self, kernel=self)
8284

8385
self.shell.configurables.append(self.comm_manager)
84-
comm_msg_types = [ 'comm_open', 'comm_msg', 'comm_close' ]
85-
for msg_type in comm_msg_types:
86+
for msg_type in self.comm_msg_types:
8687
self.shell_handlers[msg_type] = getattr(self.comm_manager, msg_type)
8788

8889
if _use_appnope() and self._darwin_app_nap:
@@ -522,6 +523,16 @@ def do_clear(self):
522523
self.shell.reset(False)
523524
return dict(status='ok')
524525

526+
def should_dispatch_immediately(self, msg, *args):
527+
try:
528+
msg_type = msg['header']['msg_type']
529+
if msg_type in self.comm_msg_types:
530+
return True
531+
except ValueError:
532+
pass
533+
534+
return False
535+
525536

526537
# This exists only for backwards compatibility - use IPythonKernel instead
527538

0 commit comments

Comments
 (0)