python 多线程(多个线程一起返回结果)


	python  多线程(多个线程一起返回结果)
[编程语言教程]

待整理:

测试代码:

‘‘‘
Created on 2020年7月21日

@author: sea
‘‘‘
from concurrent.futures.thread import ThreadPoolExecutor
from concurrent.futures._base import as_completed
from time import sleep


def send_request(req_url,json):
#     print(req_url+ "     "+json)
    sleep(3)
    return req_url
    
    
    
if __name__ == ‘__main__‘:
    executor = ThreadPoolExecutor(max_workers=3)
    all_task=[]
    for i in range(10):
        pass
        task = executor.submit(send_request,"url--"+ str(i),str(i)+"json")
        all_task.append(task)
        print("all_task size is "+str(len(all_task)))
    for future in as_completed(all_task):
        pass
        result = future.result()
        print(result)
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » python 多线程(多个线程一起返回结果)