python 多线程(多个线程一起返回结果)
2021-04-12 09:25
标签:cut auth import RKE ase send creat color end 待整理: 测试代码: python 多线程(多个线程一起返回结果) 标签:cut auth import RKE ase send creat color end 原文地址:https://www.cnblogs.com/lshan/p/13356788.html‘‘‘
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)
下一篇:Java多线程基础
文章标题:python 多线程(多个线程一起返回结果)
文章链接:http://soscw.com/index.php/essay/74647.html