Skip to content

Commit 474093f

Browse files
authored
Use non-blocking zmq Poller (#1023)
* Use non-blocking zmq Poller * Pin pytest<8.2.0 * Fix mypy * Apply review comment --------- Co-authored-by: Frédéric Collonval <[email protected]>
1 parent 0236973 commit 474093f

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

jupyter_client/asynchronous/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AsyncKernelClient(KernelClient):
3333
raising :exc:`queue.Empty` if no message arrives within ``timeout`` seconds.
3434
"""
3535

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

3838
def _context_default(self) -> zmq.asyncio.Context:
3939
self._created_context = True

jupyter_client/channels.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ def _recv(self, **kwargs: t.Any) -> t.Dict[str, t.Any]:
223223
def get_msg(self, timeout: t.Optional[float] = None) -> t.Dict[str, t.Any]:
224224
"""Gets a message if there is one that is ready."""
225225
assert self.socket is not None
226-
if timeout is not None:
227-
timeout *= 1000 # seconds to ms
228-
ready = self.socket.poll(timeout)
226+
timeout_ms = None if timeout is None else int(timeout * 1000) # seconds to ms
227+
ready = self.socket.poll(timeout_ms)
229228
if ready:
230229
res = self._recv()
231230
return res
@@ -305,9 +304,8 @@ async def get_msg( # type:ignore[override]
305304
) -> t.Dict[str, t.Any]:
306305
"""Gets a message if there is one that is ready."""
307306
assert self.socket is not None
308-
if timeout is not None:
309-
timeout *= 1000 # seconds to ms
310-
ready = await self.socket.poll(timeout)
307+
timeout_ms = None if timeout is None else int(timeout * 1000) # seconds to ms
308+
ready = await self.socket.poll(timeout_ms)
311309
if ready:
312310
res = await self._recv()
313311
return res

jupyter_client/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ async def _async_execute_interactive(
530530
else:
531531
timeout_ms = None
532532

533-
poller = zmq.Poller()
533+
poller = zmq.asyncio.Poller()
534534
iopub_socket = self.iopub_channel.socket
535535
poller.register(iopub_socket, zmq.POLLIN)
536536
if allow_stdin:
@@ -544,7 +544,7 @@ async def _async_execute_interactive(
544544
if timeout is not None:
545545
timeout = max(0, deadline - time.monotonic())
546546
timeout_ms = int(1000 * timeout)
547-
events = dict(poller.poll(timeout_ms))
547+
events = dict(await poller.poll(timeout_ms))
548548
if not events:
549549
emsg = "Timeout waiting for output"
550550
raise TimeoutError(emsg)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test = [
5151
"mypy",
5252
"paramiko; sys_platform == 'win32'",
5353
"pre-commit",
54-
"pytest",
54+
"pytest<8.2.0",
5555
"pytest-jupyter[client]>=0.4.1",
5656
"pytest-cov",
5757
"pytest-timeout",

0 commit comments

Comments
 (0)