当前位置 : 主页 > 手机开发 > ROM >

线程池和进程池

来源:互联网 收集:自由互联 发布时间:2021-06-10
# # 线程池# import time# from concurrent.futures import ThreadPoolExecutor## pool = ThreadPoolExecutor(15)### def task(n1):# time.sleep(1)# print(f‘任务{n1}‘)### num = int(input(‘请输入任务个数:‘))# for i in range(num)
# # 线程池# import time# from concurrent.futures import ThreadPoolExecutor## pool = ThreadPoolExecutor(15)### def task(n1):#     time.sleep(1)#     print(f‘任务{n1}‘)### num = int(input(‘请输入任务个数:‘))# for i in range(num):#     pool.submit(task, i, num)## pool.shutdown(True)## print(‘ENd‘)## pool.map(task, range(100))# print(‘END‘)# 进程池import timefrom concurrent.futures import ProcessPoolExecutordef task(n1):    time.sleep(0.2)    print(f‘任务{n1}‘)if __name__ == ‘__main__‘:    pool = ProcessPoolExecutor(10)    for i in range(100):        pool.submit(task, i)    print(‘END‘)
网友评论