从品牌网站建设到网络营销策划,从策略到执行的一站式服务
import threading
from concurrent import futures
import logging
import time
FORMAT = '%(processName)s %(threadName)s %(process)d %(thread)d %(message)s'
logging.basicConfig(level=logging.INFO, format=FORMAT)
def worker(n):
logging.info('begin to work{}'.format(n))
time.sleep(5)
logging.info('finished {}'.format(n))
executor = futures.ThreadPoolExecutor(max_workers=3)
fs = []
for i in range(3):
future = executor.submit(worker, i)
fs.append(future)
for i in range(3, 6):
future = executor.submit(worker, i)
fs.append(future)
while True:
time.sleep(2)
logging.info(threading.enumerate())
flag = True
for f in fs:
logging.info(f.done)
flag = flag and f.done()
if flag:
executor.shutdown() # 清理池
logging.info(threading.enumerate())
break
# 如果想改成进程,只需要将 ThreadPoolExecutor 改成 ProcessPoolExecutor
# 但是注意,一定要写在 __name__ == '__main__' 代码块下
成都网站建设公司地址:成都市青羊区太升南路288号锦天国际A座10层 建设咨询028-86922220
成都快上网科技有限公司-四川网站建设设计公司 | 蜀ICP备19037934号 Copyright 2020,ALL Rights Reserved cdkjz.cn | 成都网站建设 | © Copyright 2020版权所有.
专家团队为您提供成都网站建设,成都网站设计,成都品牌网站设计,成都营销型网站制作等服务,成都建网站就找快上网! | 成都网站建设哪家好? | 网站建设地图