Python 3.x 使用concurrent.futures.ProcessPoolExecutor进行多处理是否不好?

Python 3.x 使用concurrent.futures.ProcessPoolExecutor进行多处理是否不好?,python-3.x,multiprocessing,Python 3.x,Multiprocessing,我的一个朋友告诉我,下面的代码片段中有一个性能错误。他告诉我改用map或imap。我不明白怎么了。我应该使用多处理包吗?如何改进 with concurrent.futures.ProcessPoolExecutor() as executor: result = list(future.result() for future in [ executor.submit(do_something, id) for id in [1,2,3

我的一个朋友告诉我,下面的代码片段中有一个性能错误。他告诉我改用
map
imap
。我不明白怎么了。我应该使用
多处理
包吗?如何改进

with concurrent.futures.ProcessPoolExecutor() as executor:
    result = list(future.result() for future in
                          [ executor.submit(do_something, id) for id in [1,2,3] ])
根据,ProcessPoolExecutor已经使用了多处理模块

ProcessPoolExecutor类是一个Executor子类,它使用进程池异步执行调用。ProcessPoolExecutor使用多处理模块,这允许它绕过全局解释器锁,但也意味着只能执行和返回可拾取的对象


那么,按原样使用是否完全合适?如果我使用executor.map()而不是submit怎么办?在问题代码中,在创建所有未来之后调用
future.result()
。因此,所有期货都是并行运行的,没有阻塞;只有获取结果才会以阻塞方式进行。你的朋友说问题出在哪里?@Mistermiagi他告诉我不应该使用future,因为它没有充分利用cpu。他告诉我用地图或imap代替。