Skip to content

Commit

Permalink
fix: Use the same timeout mechanism to pyzmq's own auth test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Feb 28, 2024
1 parent 999cd4e commit bfc4805
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/callosum/lower/zeromq.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,6 @@ def __init__(
self._attach_monitor = attach_monitor
self._zsock_opts = {**_default_zsock_opts, **(zsock_opts or {})}

async def ping(self, ping_timeout: Optional[int] = None) -> bool:
assert self._main_sock is not None
sock: zmq.asyncio.Socket = self._main_sock
await sock.send_multipart([b"PING", b"", b""])
async with asyncio.timeout(ping_timeout / 1000 if ping_timeout else None):
response = await sock.recv_multipart()
return response[0] == b"PONG"

async def __aenter__(self):
if not self.transport._closed:
return ZeroMQRPCConnection(self.transport)
Expand Down Expand Up @@ -395,9 +387,13 @@ async def ping(self, ping_timeout: Optional[int] = None) -> bool:
assert self._main_sock is not None
sock: zmq.asyncio.Socket = self._main_sock
await sock.send_multipart([b"PING", b"", b""])
async with asyncio.timeout(ping_timeout / 1000 if ping_timeout else None):
response = await sock.recv_multipart()
return response[0] == b"PONG"
if await sock.poll(ping_timeout):
try:
response = await sock.recv_multipart(zmq.NOBLOCK)
except zmq.Again:
return False
return response[0] == b"PONG"
return False

async def __aenter__(self) -> ZeroMQRPCConnection:
if not self.transport._closed:
Expand Down

0 comments on commit bfc4805

Please sign in to comment.