首页 > 编程语言 > 详细

线程池:ThreadPoolExecutor

时间:2020-12-24 00:50:43      阅读:34      评论:0      收藏:0      [点我收藏+]
# __author: "ZXYang"
# date: 2020/12/23


"""
max_workers:最多执行任务数(cpu核数 x 5 )
submit:线程池中提交任务
"""

import time
from concurrent.futures.thread import ThreadPoolExecutor


def work1():
print("==========work1==========")
for i in range(6):
time.sleep(0.5)
print(f‘work1:第{i+1}秒‘)


def work2():
print("===========work2=========")
for i in range(6):
time.sleep(0.5)
print(f‘work2:第{i+1}秒‘)


with ThreadPoolExecutor(max_workers=6 * 5) as f:
f.submit(work1)
f.submit(work2)

线程池:ThreadPoolExecutor

原文:https://www.cnblogs.com/zxy01/p/14181689.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!