您好,欢迎来到爱够旅游网。
搜索
您的当前位置:首页Python标准模块--concurrent.futures模块(ThreadPoolExecutor:线程池,提供异步调用、ProcessPoolExecutor: 进程池,提供异步调用)

Python标准模块--concurrent.futures模块(ThreadPoolExecutor:线程池,提供异步调用、ProcessPoolExecutor: 进程池,提供异步调用)

来源:爱够旅游网


1 介绍
concurrent.futures模块提供了高度封装的异步调用接口
ThreadPoolExecutor:线程池,提供异步调用
ProcessPoolExecutor: 进程池,提供异步调用
Both implement the same interface, which is defined by the abstract Executor class.

2 基本方法
●submit(fn, *args, **kwargs)
异步提交任务

●map(func, *iterables, timeout=None, chunksize=1) 
取代for循环submit的操作

●shutdown(wait=True) 
相当于进程池的pool.close()+pool.join()操作
wait=True,等待池内所有任务执行完毕回收完资源后才继续
wait=False,立即返回,并不会等待池内的任务执行完毕
但不管wait参数为何值,整个程序都会等到所有任务执行完毕
submit和map必须在shutdown之前

●result(timeout=None)
取得结果

●add_done_callback(fn)
回调函数

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务