码迷,mamicode.com
首页 > 编程语言 > 详细

Python的并发并行[4] -> 并发 -> concurrent.future 模块

时间:2018-01-01 16:55:52      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:自动   执行器   返回   new   ase   mil   并行   常量   man   

concurrent.future 模块


 

1 thread模块 / thread Module

 

1.1 常量 / Constants

Pass

1.2 函数 / Function

Pass

1.3 / Class

1.3.1 ThreadPoolExecutor

类实例化:executor = ThreadPoolExecutor(max_works)

类的功能:用于生成一个线程池执行器实例,其基类是_base.Executor

传入参数: max_works

max_works: int类型,线程池最大线程的数量

返回参数: executor

executor: instance类型,线程池执行器实例

1.3.1.1 submit()函数

函数调用: executor.submit(fn, *args)

函数功能:启动线程池的一个线程,调用传入的fn函数及其参数

传入参数: fn, *args

fn: function类型,传入的函数,被线程池启动的线程调用

*args: fn所需的参数,当有多个时,传入方式为submit(fn, args_1, args_2, args_3)

返回参数:

1.3.1.2 map()函数

函数调用: iter = executor.map(fn, *iterables, timeout=None)

函数功能:返回一个迭代生成器,类比于map(fn, *iterables),属于基类Executor的方法

传入参数: fn, *args, timeout

fn: function类型,传入的函数,被线程池启动的线程调用

*iterables: list/tuple等可迭代的类型,通过迭代获取,传入fn函数中。当有多个参数时,传入方式为map(fn, [a_args_1, a_args_2, ..., a_args_n], [b_args_1, b_args_2, …, b_args_n], iterable_3),map会对生成器进行迭代,分别传入参数给fn

返回参数: iter

iter: generator类型,会无序地自动调用函数进行迭代,结束后剩下None

 

2 process 模块 / process Module

TBD

Python的并发并行[4] -> 并发 -> concurrent.future 模块

标签:自动   执行器   返回   new   ase   mil   并行   常量   man   

原文地址:https://www.cnblogs.com/stacklike/p/8167092.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!