Skip to content
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

Use non-blocking zmq Poller #1023

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion jupyter_client/asynchronous/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AsyncKernelClient(KernelClient):
raising :exc:`queue.Empty` if no message arrives within ``timeout`` seconds.
"""

context = Instance(zmq.asyncio.Context)
context = Instance(zmq.asyncio.Context) # type:ignore[arg-type]

def _context_default(self) -> zmq.asyncio.Context:
self._created_context = True
Expand Down
2 changes: 1 addition & 1 deletion jupyter_client/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def _recv(self, **kwargs: t.Any) -> t.Dict[str, t.Any]:
ident, smsg = self.session.feed_identities(msg)
return self.session.deserialize(smsg)

def get_msg(self, timeout: t.Optional[float] = None) -> t.Dict[str, t.Any]:
def get_msg(self, timeout: t.Optional[int] = None) -> t.Dict[str, t.Any]:
Copy link
Member

Choose a reason for hiding this comment

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

This should accept a float. get_msg(timeout=0.25) is valid. The cast to int should happen after multiplying by 1000 to get ms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review @minrk

I corrected it in 733bd59 (applying the same changes for the async case that was not flagged).

"""Gets a message if there is one that is ready."""
assert self.socket is not None
if timeout is not None:
Expand Down
4 changes: 2 additions & 2 deletions jupyter_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ async def _async_execute_interactive(
else:
timeout_ms = None

poller = zmq.Poller()
poller = zmq.asyncio.Poller()
iopub_socket = self.iopub_channel.socket
poller.register(iopub_socket, zmq.POLLIN)
if allow_stdin:
Expand All @@ -544,7 +544,7 @@ async def _async_execute_interactive(
if timeout is not None:
timeout = max(0, deadline - time.monotonic())
timeout_ms = int(1000 * timeout)
events = dict(poller.poll(timeout_ms))
events = dict(await poller.poll(timeout_ms))
if not events:
emsg = "Timeout waiting for output"
raise TimeoutError(emsg)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test = [
"mypy",
"paramiko; sys_platform == 'win32'",
"pre-commit",
"pytest",
"pytest<8.2.0",
"pytest-jupyter[client]>=0.4.1",
"pytest-cov",
"pytest-timeout",
Expand Down
Loading