英文:
Is there an easy "tqdm like" way to make a for loop to run multiprocess?
问题
我有一个在Python中的for循环,我想在多个进程中运行。我知道我可以使用multiprocessing
模块来实现这一点,但我想知道是否有一个库可以让我用类似于tqdm
的简单语法来实现这个。这是我想要实现的:
for i in some_multiprocess_library(range(100), n_processes=4):
some_func(i)
英文:
I have a for loop in Python that I want to run in multiple processes. I know I can use the multiprocessing
module to achieve this, but I was wondering if there is a library that allows me to do this with a simple syntax similar to how tqdm
works. Here is what I want to achieve:
for i in some_multiprocess_library(range(100), n_processes=4):
some_func(i)
</details>
# 答案1
**得分**: 1
```python
from tqdm.contrib.concurrent import process_map
for i in process_map(range(1_000)):
some_func(i)
同样的建议也适用于Python的multiprocessing
模块。
英文:
You can use:
from tqdm.contrib.concurrent import process_map
for i in process_map(range(1_000)):
some_func(i)
The same recommendations from the Python multiprocessing
modules apply.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论