有多线程的map()函数吗? [英] Is there a multithreaded map() function?

查看:42
本文介绍了有多线程的map()函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个没有副作用的功能.我想对数组中的每个元素运行它,并返回一个包含所有结果的数组.

I have a function that is side-effect free. I would like to run it for every element in an array and return an array with all of the results.

Python可以生成所有值吗?

Does Python have something to generate all of the values?

推荐答案

尝试通过多处理进行Pool.map函数:

Try the Pool.map function from multiprocessing:

http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers

它本身不是多线程的,但这实际上是很好的,因为GIL在Python中严重破坏了多线程.

It's not multithreaded per-se, but that's actually good since multithreading is severely crippled in Python by the GIL.

这篇关于有多线程的map()函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆