线程池和进程池

# # 线程池
# 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 time
from concurrent.futures import ProcessPoolExecutor


def 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')
posted @ 2019-09-19 15:53  徐-  阅读(111)  评论(0编辑  收藏  举报