test.py 1.26 KB
Newer Older
AnHui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
# -*- ecoding: utf-8 -*-
# @ModuleName: test
# @Function: 
# @Author: 安辉
# @Time: 2022/1/19 5:49 下午

from itertools import combinations, product
from multiprocessing import Pool
import os, time
from tqdm import tqdm
import time


tmp = product((1, 2, 3), [4, 5], (6, 7))
print(list(tmp))


# for i in tqdm(range(100)):
#     # print('测试')
#     time.sleep(0.1)
#     print('')

# def work(n):
#     print('%s run' % os.getpid())
#     time.sleep(3)
#     return n ** 2
#
#
# if __name__ == '__main__':
#     p = Pool(3)  # 进程池中从无到有创建三个进程,以后一直是这三个进程在执行任务
#     res_l = []
#     for i in range(10):
#         res = p.apply_async(work, args=(i,))  # 同步运行,阻塞、直到本次任务执行完毕拿到res
#         res_l.append(res)
#
#     # 异步apply_async用法:如果使用异步提交的任务,主进程需要使用jion,等待进程池内任务都处理完,然后可以用get收集结果,否则,主进程结束,进程池可能还没来得及执行,也就跟着一起结束了
#     p.close()
#     p.join()
#     for res in res_l:
#         print(res.get())  # 使用get来获取apply_aync的结果,如果是apply,则没有get方法,因为apply是同步执行,立刻获取结果,也根本无需get