Skip to content

Creates and register the comm target when it does not exist#698

Merged
JohanMabille merged 1 commit into
jupyter-xeus:mainfrom
JohanMabille:create_comm
Mar 23, 2026
Merged

Creates and register the comm target when it does not exist#698
JohanMabille merged 1 commit into
jupyter-xeus:mainfrom
JohanMabille:create_comm

Conversation

@JohanMabille

@JohanMabille JohanMabille commented Mar 23, 2026

Copy link
Copy Markdown
Member

Fixes #672

@martinRenou

Copy link
Copy Markdown
Member

Does it work to re-register the comm target after the fact?

import comm

# This creates a dummy callback
comm.create_comm(target_name="foo")

def handle_comm_opened(*args, **kwargs):
    # TODO handle comm open from front-end
    pass


comm_manager = comm.get_comm_manager()
if comm_manager is not None:
    comm_manager.register_target("foo", handle_comm_opened)

@JohanMabille

Copy link
Copy Markdown
Member Author

It is supposed to work because the registration ends here. However, executing this coe in a single cell results in a kernel crash for another reason (the GIL is not handled correctly). Splitting the code in the two following cells:

import comm

# This creates a dummy callback
comm.create_comm(target_name="foo")

and

def handle_comm_opened(*args, **kwargs):
    # TODO handle comm open from front-end
    pass


comm_manager = comm.get_comm_manager()
if comm_manager is not None:
    comm_manager.register_target("foo", handle_comm_opened)

makes it work.

The issue seems to come from the call of comm_close received after creating the comm. If we have any python left to execute from the cell, it crashes. I'll investigate and fix that one in a dedicated PR.

@JohanMabille JohanMabille merged commit 74272e9 into jupyter-xeus:main Mar 23, 2026
15 checks passed
@JohanMabille JohanMabille deleted the create_comm branch March 23, 2026 14:14
@JohanMabille

Copy link
Copy Markdown
Member Author

Looks like the issue is in xeus itself, so let's release xeus-python to fix the most common issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

python comm crashes XPython kernel

2 participants