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

目录

ProcessPoolExecutor: 进程池

ThreadPoolExecutor:线程池 

map的用法 

回调函数


https://docs.python.org/dev/library/concurrent.futures.html

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)
回调函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值