Python 属性错误:';ListProxy';对象没有属性';复印件';

Python 属性错误:';ListProxy';对象没有属性';复印件';,python,python-3.x,python-multiprocessing,Python,Python 3.x,Python Multiprocessing,Python 3.5 我正在尝试并行化下面的代码,为此,我使用了来自多处理模块的ListProxy对象,以便访问列表的工作人员以一种受管理的方式执行此操作。我知道来自多处理模块的代理对象是不可编辑的,但是您可以调用对象上的copy()函数来返回该对象的常规版本,即DictProxy上的copy()返回一个您可以迭代的常规Dict def getAllLabels(graph: UndirectedGraph, graphSize: int, probabilityList: list) ->

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
但是,每次调用list对象上的copy()时,都会出现以下错误:

Traceback (most recent call last):
File "src/network_motifs.py", line 10, in <module>
subgraphs = esu.getAllLabels(graph, 4, [1, 1, 1, 1])
File "/home/erik/Git/nemolib-python-library/src/nemolib/esu/esu.py", line 39, in    getAllLabels
getSubgraphs(graph, graphSize, nodeList, neighborList, exclusionList, subgraphList.copy(), probabilityList)
AttributeError: 'ListProxy' object has no attribute 'copy'
回溯(最近一次呼叫最后一次):
文件“src/network_motions.py”,第10行,在
子图=esu.getAllLabels(图,4,[1,1,1,1])
文件“/home/erik/Git/nemolib python library/src/nemolib/esu/esu.py”,第39行,在getAllLabels中
getSubgraphs(图形、graphSize、节点列表、邻居列表、排除列表、subgraphList.copy()、probabilityList)
AttributeError:“ListProxy”对象没有属性“copy”
尝试使用

subgraphList[:]
而不是subgraphList.copy(),因为您的子图列表可能没有那样实现.copy()方法

否则,可选择:

import copy
newsubgraphList = copy.copy(subgraphList)
试用

subgraphList[:]
而不是subgraphList.copy(),因为您的子图列表可能没有那样实现.copy()方法

否则,可选择:

import copy
newsubgraphList = copy.copy(subgraphList)
如果执行dir(subgraphList),则可以看到LitProxy对象可能具有的方法

['_Client', '__add__', '__builtins__', '__class__', '__contains__', '__deepcopy__', '__delattr__', '__delitem__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__le__', '__len__', '__lt__', '__module__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_address_to_local', '_after_fork', '_authkey', '_callmethod', '_close', '_connect', '_decref', '_exposed_', '_getvalue', '_id', '_idset', '_incref', '_manager', '_mutex', '_owned_by_manager', '_serializer', '_tls', '_token', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
正如您所见,它有一个可以使用的deepcopy方法

subgraphList.__deepcopy__({})
此外,deepcopy确保它甚至复制嵌套项

,如果执行dir(subgraphList),则可以看到LitProxy对象具有的可能方法

['_Client', '__add__', '__builtins__', '__class__', '__contains__', '__deepcopy__', '__delattr__', '__delitem__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__le__', '__len__', '__lt__', '__module__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_address_to_local', '_after_fork', '_authkey', '_callmethod', '_close', '_connect', '_decref', '_exposed_', '_getvalue', '_id', '_idset', '_incref', '_manager', '_mutex', '_owned_by_manager', '_serializer', '_tls', '_token', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
正如您所见,它有一个可以使用的deepcopy方法

subgraphList.__deepcopy__({})

另外,deepcopy确保它复制嵌套项,即使嵌套项

列表
没有。
.copy()
首先,这与多处理没有多大关系。@AKX列表有一个复制方法:-),因为python 3.3
列表
没有
.copy()
,这与多处理无关。@自python 3.3以来,AKX列表有一个复制方法:-)