[代码]并发执行python的例子

import  threading

def _task(func, args, n_thread=8):
    # 多线程并发执行所有任务
    threads = map(lambda : threading.Thread(target=func, args=args), range(len(n_thread)))  
    map(lambda th: th.start(), threads)  
    map(lambda th: th.join(), threads)
from concurrent.futures import ThreadPoolExecutor

def _query(SQLs):
    pool = ThreadPoolExecutor(max_workers=len(SQLs))
    jobs = [(k, pool.submit(query, sql) ) for k,sql in SQLs ]    
    pool.shutdown()
    for k, p1 in jobs:
        print(p1.result())
原文地址:https://www.cnblogs.com/bregman/p/13728778.html