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

Is ZmqClientTransport thread-safe? #40

Closed fxsjy closed 7 years ago

fxsjy commented 7 years ago

I tried to call same rpc client object in multi-threads,and got some exceptions raised by zmq.

lnoor commented 7 years ago

Short answer: No it isn't.

I must admit I didn't try to share any tinyrpc instance between threads. But checking the code I do not think that any part of tinyrpc is thread safe. So the problems you experience are probably not unique for zmq.

If you really must share any tinyrpc instance between threads you should provide your own locking or local storage mechanism. Tinyrpc really isn't designed for this use case.

However, giving each thread its own client should work. Do let me know if that scenario doesn't work.

fxsjy commented 7 years ago

@lnoor , thank you. I added a lock myself before call tinyrpc client, then it solved the problem.