So, I'm playing around with ZeroRPC and Tornado for a pet project and I've run into some issues using ZeroRPC in conjunction with python
's multiprocessing library. Specifically, I'm creating and running new ZeroRPC servers programmatically, but typically when run, the zerorpc
server is blocking, so my thought was to throw it into another process like so:
server = zerorpc.Server(FuncWrapper())
server.bind(server_address)
process = multiprocessing.Process(target=server.run)
process.start()
However, when I do this, calling the RPC
server just hangs, which is typical behavior when an endpoint hasn't been correctly instantiated. However, if I just let the server running block and call it like so:
serhouldver = zerorpc.Server(FuncWrapper())
server.bind(server_address)
server.run()
Everything works fine. My understanding was that these two implementations should be equivalent, but somehow they are not.
Any ideas?
zerorpc uses gevent for cooperative asynchronous IO. You might want to look into how tornado, multiprocessing and gevent are playing all together.
For what I can tell in:
Line 1 and 2 are creating and binding a port on the current process. But at line 3 and 4, what I can guess happening is:
Without testing, I can only guess that running zerorpc completely in the new process should work:
Then via some Manager object or other Shared memory services offered by multiprocess, you could make the zerorpc server in the new process access and share data with your local process.
On a side note, if what you are trying to do, is call server.run() without blocking, if you were using only gevent, I would tell you to simply run it in its own coroutine:
Maybe you can call
server.run
from a tornado coroutine/asyunc function directly. Maybe there is a way to integrate gevent and tornado (like this link suggest: https://bmmh.wordpress.com/2012/10/07/tornado-and-gevent/), I don't know enough to help you at this point.