Skip to content

Commit 96f43e7

Browse files
sonthonaxrkdavidbrochart
authored andcommitted
Issue #12786: Implement hook for Comm messages
1 parent a8a4e2c commit 96f43e7

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
@@ -68,6 +68,8 @@ def _user_ns_changed(self, change):
6868
_sys_raw_input = Any()
6969
_sys_eval_input = Any()
7070

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

@@ -95,8 +97,7 @@ def __init__(self, **kwargs):
9597
self.comm_manager = CommManager(parent=self, kernel=self)
9698

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

102103
if _use_appnope() and self._darwin_app_nap:
@@ -566,6 +567,16 @@ def do_clear(self):
566567
self.shell.reset(False)
567568
return dict(status='ok')
568569

570+
def should_dispatch_immediately(self, msg):
571+
try:
572+
msg_type = msg['header']['msg_type']
573+
if msg_type in self.comm_msg_types:
574+
return True
575+
except ValueError:
576+
pass
577+
578+
return False
579+
569580

570581
# This exists only for backwards compatibility - use IPythonKernel instead
571582

0 commit comments

Comments
 (0)