Closed darksidds closed 2 years ago
I'm afraid not. From tinyrpc's perspective that is a function of the transport layer and ZeroMQ explicitly does not support time outs or connection status querying.
It probably is possible to modify ZmqClientTransport
to timeout when not receiving data.
But it will only tell you that there was no answer within a given time interval.
It won't be able to tell you if the request was not received by the server or the server took a long time to reply or the reply never made it back to the client.
I will look into that.
Note to self: use the zmq.Poller class around recv().
Thanks to you for your prompt and thorough reply!
It won't be able to tell you if the request was not received by the server or the server took a long time to reply or the reply never made it back to the client.
Falling with timeout exception is much better than eternal await.
Sorry it took so long, i got sick. In the branch https://github.com/mbr/tinyrpc/tree/lnoor/zmq-timeout is a version of ZmqClientTransport with a timeout parameter in the constructor and create functions. This optional parameter takes an integer value of milliseconds for the timeout. Can you please try this branch and verify that it serves your purpose?
Your patch looks fine.
timeout
milliseconds. Traceback (most recent call last):
File "C:\sandbox\tinyrpc_client.py", line 38, in <module>
x = str_server.long_command(40.510)
File "C:\sandbox\test-venv\lib\site-packages\tinyrpc\client.py", line 177, in <lambda>
proxy_func = lambda *args, **kwargs: self.client.call(
File "C:\sandbox\test-venv\lib\site-packages\tinyrpc\client.py", line 89, in call
rep = self._send_and_handle_reply(req, one_way)
File "C:\sandbox\test-venv\lib\site-packages\tinyrpc\client.py", line 52, in _send_and_handle_reply
reply = tport.send_message(req.serialize(), expect_reply=(not one_way))
File "C:\sandbox\test-venv\lib\site-packages\tinyrpc\transports\zmq.py", line 74, in send_message
ready = dict(poller.poll(self.timeout))
File "C:\sandbox\test-venv\lib\site-packages\zmq\sugar\poll.py", line 105, in poll
return zmq_poll(self.sockets, timeout=timeout)
File "zmq\backend\cython\_poll.pyx", line 117, in zmq.backend.cython._poll.zmq_poll
File "zmq\backend\cython\checkrc.pxd", line 13, in zmq.backend.cython.checkrc._check_rc
KeyboardInterrupt
Thanks for the feedback. I will create a new version of tinyrpc and upload it to pypi.
Thank you for the support!
I'm trying to use
ZmqClientTransport
and having a problem that ifZmqServerTransport
is offline then calling any remote function hangs. Is there a way to set up a timeout on calling functions? Or detect that server is offline?