我正在使用multiprocessing
python 3.7 中的库。
在我的用例中,我从正常list
的dict
s 开始 - 我使用它从 a 创建一个ListProxy
对象,SyncManager
然后在池中使用它来同步list
(创建如下)。
data = [{...},{...},{...}] # arbitrary list of dicts that I want to sync in a pool
with Manager() as manager:
list_proxy = manager.list()
for row in data:
list_proxy.append(manager.dict(row))
# ... list_proxy used in pool.starmap later
ListProxy
我的问题:一旦池完成运行,是否有一种 pythonic 方法可以将我的背部更改为正常列表?我查看了文档,甚至查看了源代码,似乎唯一的方法可能是使用类中的_getvalue()
方法BaseProxy
- 但这似乎很老套,而且我还必须递归地“取消代理”任何嵌套的代理对象。
我需要返回正常列表,以便稍后在代码中将其序列化为 json,ProxyObject
s 不容易序列化。