mbr / tinyrpc

A compact, modular transport and protocol agnostic RPC library. Does jsonrpc v2.
https://tinyrpc.readthedocs.org
MIT License
156 stars 53 forks source link

How to set timeout value for client calling service #41

Closed fxsjy closed 6 years ago

fxsjy commented 7 years ago

Is there a way to set timeout value for the client to call service. When server crash, the client will be blocked forever.

lnoor commented 7 years ago

Assuming you use the HttpPostClientTransport, you would do so using the transport that you pass to the client.

endpoint = 'http://example.com/jsonrpc/2.0/'

rpc_client = RPCClient(
    JSONRPCProtocol(),
    HttpPostClientTransport(endpoint)
)

You would have to extend the construction of the transport like this:

    HttpPostClientTransport(endpoint, timeout=0.1)

In case a time out happens you'd get a requests.exceptions.Timeout exception.

fxsjy commented 7 years ago

does zmqprotocol also support this option?

lnoor commented 7 years ago

No but you might use the green variant of zmq. Please check the documentation of zmq.green and tinyrpc 0mq. The source of tinyrpc's zmq transport may also provide hints.

fxsjy commented 7 years ago

thanks,I will try zmq.green later.