Skip to content

Commit 0ab59fc

Browse files
Rollo Konig BrockSylvainCorlay
Rollo Konig Brock
authored andcommitted
Issue #12786: Implement hook for Comm messages
1 parent 34014d1 commit 0ab59fc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Diff for: ipykernel/ipkernel.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def _user_ns_changed(self, change):
6767
_sys_raw_input = Any()
6868
_sys_eval_input = Any()
6969

70+
comm_msg_types = [ 'comm_open', 'comm_msg', 'comm_close' ]
71+
7072
def __init__(self, **kwargs):
7173
super(IPythonKernel, self).__init__(**kwargs)
7274

@@ -94,8 +96,7 @@ def __init__(self, **kwargs):
9496
self.comm_manager = CommManager(parent=self, kernel=self)
9597

9698
self.shell.configurables.append(self.comm_manager)
97-
comm_msg_types = [ 'comm_open', 'comm_msg', 'comm_close' ]
98-
for msg_type in comm_msg_types:
99+
for msg_type in self.comm_msg_types:
99100
self.shell_handlers[msg_type] = getattr(self.comm_manager, msg_type)
100101

101102
if _use_appnope() and self._darwin_app_nap:
@@ -555,6 +556,16 @@ def do_clear(self):
555556
self.shell.reset(False)
556557
return dict(status='ok')
557558

559+
def should_dispatch_immediately(self, msg, *args):
560+
try:
561+
msg_type = msg['header']['msg_type']
562+
if msg_type in self.comm_msg_types:
563+
return True
564+
except ValueError:
565+
pass
566+
567+
return False
568+
558569

559570
# This exists only for backwards compatibility - use IPythonKernel instead
560571

0 commit comments

Comments
 (0)