简体   繁体   English

创建可重复周期Python的工作程序

[英]Create workers for repeatable cycle Python

How I could use workers (multi processing) when for example I could use 10 at one time at most but I need them to do ~ 150 tasks. 例如,我一次最多只能使用10个工人,但我需要他们完成约150个任务,因此我该如何使用工人(多重处理)。

def main():
    for i in serverinfo :
        grabfile(i,serverinfo[i]["ip"],serverinfo[i]["psw"])

grabfile is task which I want to do with those ~10 workers, but I really don't understand how to make them work together that for example they all starter from task numbers 1-10 and then when they done they would get new tasks to do tasks 11-20 PS I refer task number as "i" in code snipet grabfile是我想与这10名工人一起完成的任务,但是我真的不明白如何使他们一起工作,例如,他们都从任务编号1-10开始,然后当他们完成时,他们将获得新任务做任务11-20 PS,我在代码片段中将任务编号称为“ i”

Use the ThreadPoolExecuter from cuncurrnt.futures cuncurrnt.futures使用ThreadPoolExecuter

It should look something like this: 它看起来应该像这样:

import concurrent.futures

pool = concurrent.futures.ThreadPoolExecutor(10) # max 10 worker threads

for x in data_to_work_on:
    pool.submit(worker_function, x.param1, x.param2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM