Skip to content

Commit 872a1e8

Browse files
sonthonaxrkdavidbrochart
authored andcommitted
Issue #12786: Implement hook for Comm messages
1 parent 953eb4b commit 872a1e8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
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

ipykernel/kernelbase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def should_handle(self, stream, msg, idents):
300300
return False
301301
return True
302302

303-
async def dispatch_shell(self, msg):
303+
async def dispatch_shell(self, msg, idents=None):
304304
"""dispatch shell requests"""
305305

306306
# flush control queue before handling shell requests

0 commit comments

Comments
 (0)