使用multiprocessing.connection模块,无法与“其他”机器通信?

时间:2014-10-02 15:38:18

标签: python multiprocessing pipe

我已将Listener和Client函数包装在程序中,以便在客户端和服务器之间发送和接收信息。地址是(' localhost',6000)或者它可以正常工作 (' ip_of_localhost',6000)。其中ip_of_localhost是一些正常规范的xxx.yyy.zzz.aaa。但是,当我尝试通过网络进行通信时,它会失败并说他们机器拒绝连接。我意识到这可能是其他阻塞元素,防火墙规则,路由器配置等。我不是在这里询问是否是这种情况。但是,下面的代码中是否有任何错误来执行任务?我错过了什么吗?

def readpipe(addr, phase=False):
    """
    Get data from a pipe ... matlab or python can send it ...
    """

    headers = None
    matrix = None
    name = None
    address = addr
    print "Address {}".format(address)
    listener = Listener(address, authkey='secret password')
    conn = listener.accept()
    print 'Connection accepted from ', listener.last_accepted
    count = 0
    while True:
        msg = conn.recv()
        count +=1
#        print "msg {}\n{}".format(count, msg)
        if name == None:
            name = msg
        elif headers == None:
            headers = msg
        elif matrix == None:
            matrix = msg
        if msg == 'close':
            conn.close()
            break
    listener.close()

    if headers[0] != 'Frequency':
        headers[0] = 'Frequency'
        print "Column 0 should be Frequncy for TestEVAL to know the X axis"

    data = matrix_to_dict(matrix, headers)
    return data, headers, name


def writepipe(address, headers, data, name, phase=False):
    """
    Write dataset to a pipe ...
    """

    conn = Client(address, authkey='secret password')
    conn.send(name)
    conn.send(headers)
    conn.send(data)
    conn.send('close')
    conn.close()    

0 个答案:

没有答案