Skip to content

Fix blocking issue in Voila (nbclient case) #1059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 0 additions & 4 deletions jupyter_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,6 @@ def send(
# ZMQStreams and dummy sockets do not support tracking.
track = False

if isinstance(stream, zmq.asyncio.Socket):
assert stream is not None # type:ignore[unreachable]
stream = zmq.Socket.shadow(stream.underlying)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this, it's not actually guaranteed the send will happen, since it's not awaited (zmq.asyncio does currently immediately schedule sends, but it doesn't guarantee that it will continue to do so), and the type of tracker will be incorrect Awaitable[Event] instead of Event (and a different type when copy=True vs copy=False.

We could add async polling, either here or (perhaps easier) in nbclient, so you can avoid calling this when it would block:

events = await async_socket.poll(timeout_ms, zmq.POLLOUT)
if events & zmq.POLLOUT:
    session.send(async_socket) # won't block
else:
    # ????

Copy link
Member

@JohanMabille JohanMabille Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing some bits here, but would it be possible to handle that in the AsyncZMQSocketChannel instead? I.e. overwrite the send method, do the proper stuff, and then call session.send? This would prevent the Socket wrapper from leaking into the Session class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's probably where it belongs


if isinstance(msg_or_type, (Message, dict)):
# We got a Message or message dict, not a msg_type so don't
# build a new Message.
Expand Down
Loading