Python 3.5
我正在尝试并行化下面的代码,为此我使用了来自多处理模块的ListProxy对象,以便访问该列表的工作人员以一种受管理的方式执行此操作。我知道来自多处理模块的代理对象是不可编辑的,但是您可以调用对象上的copy()函数来返回该对象的常规版本,即DictProxy上的copy()返回一个可以迭代的常规Dict。在
def getAllLabels(graph: UndirectedGraph, graphSize: int, probabilityList: list) -> list:
'''Enumerate through ESU algorithm and retrieve all subgraphs of a given size for this graph.'''
process_manager = multiprocessing.Manager()
pool = multiprocessing.Pool(4)
subgraphList = process_manager.list() #looped
exclusionList = list() #looped
for i in range(0, graph.getSize()):
nodeList = list([i])
neighborList = list() #looped
for n in graph.getAdjacencyList(i):
if n not in exclusionList and n not in nodeList and n not in neighborList:
neighborList.append(n)
#pool.apply_async(getSubgraphs, [graph, graphSize, nodeList, neighborList, exclusionList, subgraphList, probabilityList])
getSubgraphs(graph, graphSize, nodeList, neighborList, exclusionList, subgraphList.copy(), probabilityList)
exclusionList.append(i)
labels = list()
for g in subgraphList.copy():
labels.append(nodesToGraph(graph, g))
pool.close()
return labels
但是,每次对列表对象调用copy()时,都会出现以下错误:
^{pr2}$
尝试使用
而不是子图列表.复制()作为子GraphList,可能没有以这种方式实现.copy()方法。在
否则,可选择:
^{pr2}$如果使用dir(subgraphList),则可以看到LitProxy对象具有的可能方法
如您所见,它有一个可以使用的deepcopy方法
^{pr2}$此外,deepcopy还确保复制甚至嵌套的项
相关问题 更多 >
编程相关推荐