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

No response when using RPC client in multiprocess. #202

Open
QuantumEnergyE opened this issue Oct 17, 2018 · 4 comments
Open

No response when using RPC client in multiprocess. #202

QuantumEnergyE opened this issue Oct 17, 2018 · 4 comments

Comments

@QuantumEnergyE
Copy link

When I used zerorpc.Client in multiprocessing, the request to a zerorpc.Server was blocked without any response.

Note:

  • RPC Client->RPC Server(9898)->Process->RPC Client->RCP Server1(9999)
  • When I changed multiprocessing to threading, It Succeed.

CODE:

  • server.py
import multiprocessing
import zerorpc


def proxy():
    try:
        c = zerorpc.Client(timeout=3)
        c.debug = True
        c.connect("tcp://0.0.0.0:9999")
        print('connected...')
        print(c.test())
    except Exception as ex:
        print(ex)


class M(object):
    def __init__(self):
        pass

    def test(self):
        print('server test')
        p = multiprocessing.Process(target=proxy)
        p.start()
        return 'server test'


def func():
    s = zerorpc.Server(M())
    s.debug = True
    s.bind("tcp://0.0.0.0:9898")
    s.run()


func()
  • server1.py
import zerorpc


class M(object):
    def __init__(self):
        pass

    def test(self):
        print('server1 test')
        return "server1 test"


def func():
    s = zerorpc.Server(M())
    s.bind("tcp://0.0.0.0:9999")
    s.run()


func()
  • client.py
import zerorpc


def func():
    c = zerorpc.Client()
    c.debug = True
    c.connect("tcp://0.0.0.0:9898")
    print c.test()


func()

OUTPUT:

  • client.py:

server test

  • server.py:

server test
connected...

@mvheimburg
Copy link

I'm experiencing a similar problem. Did you find a solution?

@johaven
Copy link

johaven commented Jan 27, 2019

Default Python multiprocessing is not compatible with gevent (see monkey patch or use another solution: greenlet etc ...)

@LoneWolfDog
Copy link

I encounter the same questions, any solution to fix it?

@mvheimburg
Copy link

I ended up initiating all other servers before the proxy, then passing their port numbers as arguments to the proxy. Then you can make clients within the proxy to connect to the other servers.

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

4 participants