zoukankan      html  css  js  c++  java
  • 线程

    Python标准模块--concurrent.futures

    #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)
    回调函数
    
    # done()
    判断某一个线程是否完成
    
    # cancle()
    取消某个任务
  • 相关阅读:
    Math app 2.0
    “口袋精灵”单元测试
    学习进度条
    本学期总结
    sprint2的总结及团队贡献分
    点餐系统Sprint1总结
    实验8
    实验7
    实验6
    实验五
  • 原文地址:https://www.cnblogs.com/zengluo/p/12941003.html
Copyright © 2011-2022 走看看