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 Jul 15, 2021
1 parent 953eb4b commit 872a1e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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 @@ -95,8 +97,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 @@ -566,6 +567,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
2 changes: 1 addition & 1 deletion ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def should_handle(self, stream, msg, idents):
return False
return True

async def dispatch_shell(self, msg):
async def dispatch_shell(self, msg, idents=None):
"""dispatch shell requests"""

# flush control queue before handling shell requests
Expand Down

0 comments on commit 872a1e8

Please sign in to comment.