Skip to content

Commit ca2ae36

Browse files
sonthonaxrkdavidbrochart
authored andcommitted
Issue #12786: Implement hook for Comm messages
1 parent db498e0 commit ca2ae36

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
@@ -74,6 +74,8 @@ def _user_ns_changed(self, change):
7474
_sys_raw_input = Any()
7575
_sys_eval_input = Any()
7676

77+
comm_msg_types = [ 'comm_open', 'comm_msg', 'comm_close' ]
78+
7779
def __init__(self, **kwargs):
7880
super(IPythonKernel, self).__init__(**kwargs)
7981

@@ -102,8 +104,7 @@ def __init__(self, **kwargs):
102104
self.comm_manager = CommManager(parent=self, kernel=self)
103105

104106
self.shell.configurables.append(self.comm_manager)
105-
comm_msg_types = [ 'comm_open', 'comm_msg', 'comm_close' ]
106-
for msg_type in comm_msg_types:
107+
for msg_type in self.comm_msg_types:
107108
self.shell_handlers[msg_type] = getattr(self.comm_manager, msg_type)
108109

109110
if _use_appnope() and self._darwin_app_nap:
@@ -583,6 +584,16 @@ def do_clear(self):
583584
self.shell.reset(False)
584585
return dict(status='ok')
585586

587+
def should_dispatch_immediately(self, msg):
588+
try:
589+
msg_type = msg['header']['msg_type']
590+
if msg_type in self.comm_msg_types:
591+
return True
592+
except ValueError:
593+
pass
594+
595+
return False
596+
586597

587598
# This exists only for backwards compatibility - use IPythonKernel instead
588599

0 commit comments

Comments
 (0)