Python多处理 - 添加到列表的连接

时间:2016-12-01 09:20:52

标签: python pipeline python-multiprocessing

我要建立多个必须通过多个单向管道进行通信的进程。为了便于处理,我想将管道存储在列表中,如下所示:

from multiprocessing import Process, Manager, Pipe

manager = Manager()    
pipes = manager.list()

for i in range(4):
    parent_conn, child_conn = Pipe(False)
    pipes.append([parent_conn, child_conn])

#... creating processes and passing pipes[i]s to them here 

然而,这会为追加行返回错误:

RemoteErrorTraceback (most recent call last)
<ipython-input-123-dc004dda0358> in <module>()
     15     for i in range(matrixnum):
     16         parent_conn, child_conn = Pipe(False)
---> 17         pipes.append([parent_conn, child_conn])
     18 
     19     for i in range(matrixnum):

<string> in append(self, *args, **kwds)

/usr/lib/python2.7/multiprocessing/managers.pyc in _callmethod(self, methodname, args, kwds)
    772             dispatch(conn, None, 'decref', (token.id,))
    773             return proxy
--> 774         raise convert_to_error(kind, result)
    775 
    776     def _getvalue(self):

RemoteError: 
---------------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/managers.py", line 240, in serve_client
    request = recv()
TypeError: Required argument 'handle' (pos 1) not found
---------------------------------------------------------------------------

我该如何解决这个问题?

0 个答案:

没有答案