编程语言
首页 > 编程语言> > [代码]并发执行python的例子

[代码]并发执行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())

标签:map,args,python,代码,SQLs,并发,threads,th,pool
来源: https://www.cnblogs.com/bregman/p/13728778.html