你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

python 进程池不执行任务的坑

2021-11-13 7:13:58
from multiprocessing import Lock, Manager, Pool, managers
all_manager = Manager()
all_dict = all_manager.dict()
all_lock = all_manager.Lock()
def run():
    p = Pool(processes=16)
    array = [1,2,3]
    results = []
    for i in array :
        
        ret = p.apply_async(get_ths_code_by_html,
                      args=(
                          i,
                      ))
        results.append(ret)
        #r ,success = get_ths_code_by_html(ts_code_key)
    p.close()
    p.join()
    for r in results:
        print(r.get())

把 apply_async 返回的结果加到list里就ok了