python 進(jìn)程池的兩種不同實(shí)現(xiàn)方法示例
方式一:使用 multiprocessing 庫
from loguru import logger import multiprocessing def start_request(message: str) -> int: try: logger.debug(message) except Exception as error: logger.exception(error) if __name__ == "__main__": pool = multiprocessing.Pool(processes=2) for message in ['haha', 'hehe']: pool.apply_async(start_request, (message,)) pool.close() pool.join()
方式二:使用 concurrent.futures 的 ProcessPoolExecutor
from loguru import logger import multiprocessing from concurrent.futures import ProcessPoolExecutor def start_request(message: str) -> int: try: logger.debug(message) except Exception as error: logger.exception(error) if __name__ == "__main__": pool = ProcessPoolExecutor( max_workers=2 ) for message in ['haha', 'hehe']: pool.submit(start_request, message) pool.shutdown(wait=True)
以上就是python 進(jìn)程池的兩種不同實(shí)現(xiàn)示例的詳細(xì)內(nèi)容,更多關(guān)于python 進(jìn)程兩種實(shí)現(xiàn)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
深入淺出Python中三個(gè)圖像增強(qiáng)庫的使用
這篇文章主要帶大家了解一下Python中三個(gè)圖像增強(qiáng)庫的使用:Imgaug、Albumentations和SOLT,文中通過示例進(jìn)行了詳細(xì)介紹,需要的可以參考一下2022-05-05教女朋友學(xué)Python3(二)簡(jiǎn)單的輸入輸出及內(nèi)置函數(shù)查看
這篇文章主要介紹了教女朋友學(xué)Python3(二)簡(jiǎn)單的輸入輸出及內(nèi)置函數(shù)查看,涉及Python3簡(jiǎn)單的輸入輸出功能實(shí)現(xiàn),以及參看內(nèi)置函數(shù)的功能和用法描述的語句,具有一定參考價(jià)值,需要的朋友可了解下。2017-11-11深度學(xué)習(xí)TextRNN的tensorflow1.14實(shí)現(xiàn)示例
這篇文章主要介紹了深度學(xué)習(xí)TextRNN的tensorflow1.14實(shí)現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01Python多項(xiàng)式回歸的實(shí)現(xiàn)方法
這篇文章主要介紹了Python多項(xiàng)式回歸的實(shí)現(xiàn)方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-03-03Python中號(hào)稱神仙的六個(gè)內(nèi)置函數(shù)詳解
這篇文章主要介紹了Python中號(hào)稱神仙的六個(gè)內(nèi)置函數(shù),今天分享的這6個(gè)內(nèi)置函數(shù),在使用?Python?進(jìn)行數(shù)據(jù)分析或者其他復(fù)雜的自動(dòng)化任務(wù)時(shí)非常方便,需要的朋友可以參考下2022-05-05