Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ipykernel/comm/comms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
REGISTER_TARGET_COMM_TARGET_NAME = 'register_target'


def configure_comm(comm, comm_id, msg_callback):
comm.comm_id = comm_id
comm.on_msg(msg_callback)


def register_target_comm_open(comm, open_msg):
# Register a new comm target.
def msg_callback(msg):
data = msg['content']['data']
comm.kernel.comm_manager.register_target(
target_name=data['new_target_name'],
f=data['comm_open_callback']
)
configure_comm(comm, comm_id='', msg_callback=msg_callback)
7 changes: 6 additions & 1 deletion ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from IPython.utils.tokenutil import token_at_cursor, line_at_cursor
from traitlets import Instance, Type, Any, List, Bool

from .comm import CommManager
from .comm import CommManager, comms
from .kernelbase import Kernel as KernelBase
from .zmqshell import ZMQInteractiveShell

Expand Down Expand Up @@ -70,6 +70,11 @@ def __init__(self, **kwargs):
for msg_type in comm_msg_types:
self.shell_handlers[msg_type] = getattr(self.comm_manager, msg_type)

self.comm_manager.register_target(
target_name=comms.REGISTER_TARGET_COMM_TARGET_NAME,
f=comms.register_target_comm_open
)

help_links = List([
{
'text': "Python Reference",
Expand Down