并行查找Python字典

时间:2014-02-04 01:56:28

标签: python dictionary multiprocessing concurrent.futures

2个或更多进程是否可以访问单个Python字典或列表?这些进程执行只读访问,但它们会在某些时候同时访问list / dict的相同元素。我使用标准库的concurrent.futures模块尝试了以下操作,但执行时间非常慢。

from concurrent.futures import ProcessPoolExecutor

def f(x):
    return some_dictionary[x]

with ProcessPoolExecutor(max_workers=2) as executor:
    results = executor.map(f, some_list)

0 个答案:

没有答案
相关问题