av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

python concurrent.futures模塊的使用測試

瀏覽:111日期:2022-06-15 09:24:36
概述

concurrent.futures 是 3.2 中引入的新模塊,它為異步執行可調用對象提供了高層接口。可以使用 ThreadPoolExecutor 來進行多線程編程,ProcessPoolExecutor 進行多進程編程,兩者實現了同樣的接口,這些接口由抽象類 Executor 定義。這個模塊提供了兩大類型,一個是執行器類 Executor,另一個是 Future 類。執行器用來管理工作池,future 用來管理工作計算出來的結果,通常不用直接操作 future 對象,因為有豐富的 API。

說明

Python3.2開始,標準庫為我們提供了concurrent.futures模塊,它提供了ThreadPoolExecutor和ProcessPoolExecutor兩個類,實現了對threading和multiprocessing的進一步抽象,對編寫線程池/進程池提供了直接的支持.

#! /usr/bin/env python# -*- coding: utf-8 -*-## -------------------------------------------------------------------------------# Name: demo3# Author: yunhgu# Date: 2021/7/8 15:17# Description: # -------------------------------------------------------------------------------import osimport timeimport threadingfrom concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor, as_completeddef work(x): time.sleep(1) temp = f'父進程{os.getppid()}:子進程{os.getpid()}:線程{threading.get_ident()}:{x}' return tempdef sub_thread(): temp_list = [] with ThreadPoolExecutor(max_workers=3) as t:task_list = [t.submit(work, i) for i in range(5)]for task in as_completed(task_list): if task.done():temp_list.append(task.result()) return temp_listdef main(): print(f'主進程:{os.getpid()}') path_list = [] with ProcessPoolExecutor(max_workers=3) as p:task_list = [p.submit(sub_thread) for i in range(5)]for task in as_completed(task_list): if task.done():path_list.append(task.result()) for path in path_list:print(path)if __name__ == ’__main__’: main()

python concurrent.futures模塊的使用測試

不論你在什么時候開始,重要的是開始之后就不要停止。不論你在什么時候結束,重要的是結束之后就不要悔恨。

到此這篇關于python concurrent.futures模塊的使用測試 的文章就介紹到這了,更多相關python concurrent使用內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 久草色播| 亚洲第一色站 | 亚洲精品www久久久久久广东 | 国产精品久久久久久久久久久久冷 | 国产一区二区av | 久久精品91久久久久久再现 | 欧美精品国产精品 | 亚洲一区二区三区免费视频 | 中文字幕欧美日韩 | 日本黄色短片 | 免费黄色a视频 | 色综久久 | 亚洲欧美精品国产一级在线 | 亚洲一区二区三区四区五区午夜 | 一区中文字幕 | 国产激情综合五月久久 | 欧美日韩三级 | 午夜电影网| 久久精品播放 | 中文字幕日韩一区 | 亚洲在线高清 | 99久久久国产精品免费消防器 | 国产一区二区三区久久久久久久久 | 视频在线观看一区二区 | 久夜精品 | 亚洲午夜精品视频 | 一级做受毛片免费大片 | 一级aaaa毛片 | 99pao成人国产永久免费视频 | 欧美日韩福利 | 欧美精品一区二区三区蜜桃视频 | 中文字幕97 | 一区二区三区国产精品 | 久久夜色精品国产 | 久久看看 | 日韩欧美亚洲 | 在线视频99 | 91一区二区 | 久久久www成人免费无遮挡大片 | 精品永久 | 嫩草视频在线免费观看 |