[英]Python parallel append to proxy list return 'function' object is not iterable or 'NoneType' object is not iterable
我想附加列表Python並行處理。 我寫代碼如下:
from joblib import Parallel
from multiprocessing.managers import BaseManager
manager = multiprocessing.Manager()
inputs = enumerate(my_list)
lproxy = manager.list()
d = lproxy
d.append([]) #init empty list
num_cores = multiprocessing.cpu_count()
_ = Parallel(n_jobs=num_cores)(d[0].append(word) for idx, word in inputs)
然后我的並行作業返回'NoneType'對象不可迭代。 在上述情況下如何附加到列表? 在第二個例子中,我測試Parallel如下:
from joblib import Parallel, delayed
def process(word) :
print(word)
results = Parallel(n_jobs=num_cores)(delayed(process(word)) for idx, word in inputs)
並且此返回'function'對象不可迭代。 這個功能必須以某種方式特別編寫嗎?
什么是並行追加到列表中的上帝實踐?
這似乎是一個解決方案:
import multiprocessing
inputs = enumerate(my_list)
manager = multiprocessing.Manager()
lproxy = manager.list()
from joblib import Parallel, delayed
def process(word) :
lproxy.append(word)
results = Parallel(n_jobs=num_cores)(delayed(process)(word) for idx, word in inputs)
比提取代理列表我使用:
l = lproxy[:]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.