如何在多进程中创建嵌套的共享对象?-比如嵌套列表?
import multiprocessing
if __name__ == '__main__':
manager = multiprocessing.Manager()
processors = 5
'''This is what I am trying to replicate'''
# MASTER = [[[], [], []] for _ in range(processors)]
MASTER = manager.list()
for number in range(processors):
MASTER.append(manager.list())
index = MASTER.index(number)
for _ in range(3):
MASTER[index].append(manager.list())
print(MASTER)
当尝试运行此代码时,我收到一个ValueError。
Traceback (most recent call last):
File "C:/Users/engli/PycharmProjects/pythonProject/16/04/15/07/newtest.py", line 12, in <module>
index = MASTER.index(number)
File "<string>", line 2, in index
找到了
import multiprocessing
if __name__ == '__main__':
manager = multiprocessing.Manager()
processors = 5
MASTER = manager.list()
for number in range(processors):
MASTER.append(manager.list())
for x in MASTER:
x.append(manager.list())
x.append(manager.list())
x.append(manager.list())