为什么使用ZeroRPC通信的嵌套多进程失败?

时间:2019-01-10 15:21:36

标签: python multiprocessing zerorpc

我在尝试生成通过ZeroRPC通信的嵌套进程时遇到问题。它永远不会超出第一个过程。子进程已创建,但ZeroRPC无法访问该子进程,因为该调用似乎已被阻止。有什么想法吗?在Linux上运行

代表以下问题的通用代码。

test.py:

import time
from multiprocessing import Process
import zerorpc
from fooserver import fooserver
from foo import Foo

port = int(str(time.time())[-5:]) + 5000
fooserver_process = Process(target=fooserver, args=(Foo(), port, ))
fooserver_process.start()
foo_client = zerorpc.Client(heartbeat=None)
foo_client.debug = True
foo_client.bind('tcp://*:%s' % port)
foo_client.test(port)
foo_client.nest()


fooserver.py:

import zerorpc
def fooserver(stuff, port):
    s = zerorpc.Server(stuff, heartbeat=None)
    s.debug = True
    s.connect("tcp://127.0.0.1:%s" % port)
    s.run()


foo.py:

from fooserver import fooserver
from multiprocessing import Process
import zerorpc
import time

class Foo():
    def __init__(self):
        self.child = int(str(time.time())[-5:]) + 5000

    def test(self, port):
        print('# HELLO FROM FOO WITH CHILD {0} on port {1} #'.format(self.child, port))

    def nest(self):
        fooserver_process = Process(target=fooserver, args=(Foo(), self.child, ))
        fooserver_process.start()
        foo_client = zerorpc.Client(heartbeat=None)
        foo_client.debug = True
        foo_client.bind('tcp://*:%s' % self.child )
        foo_client.test(self.child)
        foo_client.nest()

0 个答案:

没有答案