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 SylvainCorlay committed Apr 2, 2021
1 parent b763d54 commit 9f5fbd5
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 @@ -67,6 +67,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 @@ -94,8 +96,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 @@ -555,6 +556,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 9f5fbd5

Please sign in to comment.