Skip to content

Commit

Permalink
Issue #12786: Implement hook for Comm messages
Browse files Browse the repository at this point in the history
  • Loading branch information
sonthonaxrk authored and davidbrochart committed Dec 9, 2021
1 parent db498e0 commit ca2ae36
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def _user_ns_changed(self, change):
_sys_raw_input = Any()
_sys_eval_input = Any()

comm_msg_types = [ 'comm_open', 'comm_msg', 'comm_close' ]

def __init__(self, **kwargs):
super(IPythonKernel, self).__init__(**kwargs)

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

self.shell.configurables.append(self.comm_manager)
comm_msg_types = [ 'comm_open', 'comm_msg', 'comm_close' ]
for msg_type in comm_msg_types:
for msg_type in self.comm_msg_types:
self.shell_handlers[msg_type] = getattr(self.comm_manager, msg_type)

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

def should_dispatch_immediately(self, msg):
try:
msg_type = msg['header']['msg_type']
if msg_type in self.comm_msg_types:
return True
except ValueError:
pass

return False


# This exists only for backwards compatibility - use IPythonKernel instead

Expand Down

0 comments on commit ca2ae36

Please sign in to comment.