1

我在进程之间共享一个字典,每个进程在字典中插入一个条目,其中字典中键的值可以是列表或 gdb.Value 实例。每个进程都在做这样的事情

mydict["key"] = [[2], gdb.Value(someaddress), 3, 4]

执行上述行时,我收到以下错误,看起来像是因为我正在插入 gdb.Value,如果是 object() 实例,则此方法有效

Traceback (most recent call last):
  File "/test.py", line 631, in insert
    mydict["key"] = [[2], 1, 3, 4]
  File "<string>", line 2, in __setitem__
  File "/usr/lib/python2.7/multiprocessing/managers.py", line 774, in _callmethod
    raise convert_to_error(kind, result)
RemoteError: 
---------------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/managers.py", line 240, in serve_client
    request = recv()
TypeError: Value object creation takes only 1 argument

我也看到了另一个问题,循环遍历字典给了我以下错误

Traceback (most recent call last):
  File "/test.py", line 1214, in <module>
    for item in mydict:
  File "<string>", line 2, in __getitem__
  File "/usr/lib/python2.7/multiprocessing/managers.py", line 774, in _callmethod
    raise convert_to_error(kind, result)
4

1 回答 1

0

请发布一个失败的独立示例。这是我从您写的内容中猜测的最佳尝试,但效果很好:

import multiprocessing as mp

def e(tag, d):
    d[tag] = [[tag], tag, tag, tag]

if __name__ == '__main__':
    d = mp.Manager().dict()
    ps = []
    for i in range(4):
        ps.append(mp.Process(target=e, args=(str(i), d)))
        ps[-1].start()
    for p in ps:
        p.join()
    print(d)

它打印:

{'0': [['0'], '0', '0', '0'],
 '1': [['1'], '1', '1', '1'],
 '2': [['2'], '2', '2', '2'],
 '3': [['3'], '3', '3', '3']}
于 2017-06-21T00:32:10.923 回答