Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subprocess client rpc call without response when main process have constructed a client #219

Open
boscotsang opened this issue Jun 27, 2019 · 0 comments

Comments

@boscotsang
Copy link

I have two rpc server and the code is below

# file Server.py

import zerorpc
class Server(object):
    def __init__(self):
        pass

    def add(self, a, b):
        return a + b

if __name__ == "__main__":
    s = zerorpc.Server(Server())
    s.bind("tcp://127.0.0.1:9888")
    s.run()
# file Server2.py

import zerorpc
class Server2(object):
    def __init__(self):
        pass

    def mul(self, a, b):
        return a * b

if __name__ == "__main__":
    s = zerorpc.Server(Server2())
    s.bind("tcp://127.0.0.1:9889")
    s.run()

I constructed a rpc client in main process and connect to Server and then start a subprocess to connect to Server2. However, the rpc call was stucked.

# file clinet2.py

import zerorpc
import multiprocessing as mp

def sub_func():
    sub_client = zerorpc.Client()
    sub_client.connect("tcp://127.0.0.1:9889")
    print(sub_client.mul(3, 3))

if __name__ == "__main__":
    client = zerorpc.Client()
    client.connect("tcp://127.0.0.1:9888")
    ps = mp.Process(target=sub_func, args=())
    ps.start()
    print(client.add(3, 3))
    ps.join()

When I start subprocess and then constructed client in main process, both calls sucess.

# file client2.py

import zerorpc
import multiprocessing as mp

def sub_func():
    sub_client = zerorpc.Client()
    sub_client.connect("tcp://127.0.0.1:9889")
    print(sub_client.mul(3, 3))

if __name__ == "__main__":
    ps = mp.Process(target=sub_func, args=())
    ps.start()
    client = zerorpc.Client()
    client.connect("tcp://127.0.0.1:9888")
    print(client.add(3, 3))
    ps.join()

Python version: 3.6.8
zerorpc version: 0.6.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant