首页 > 编程语言 > 详细

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

时间:2020-09-25 11:30:18      阅读:39      评论:0      收藏:0      [点我收藏+]
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())

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

原文:https://www.cnblogs.com/bregman/p/13728778.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!