1. 程式人生 > >python 執行緒池 ThreadPoolExecutor簡單案例

python 執行緒池 ThreadPoolExecutor簡單案例

###匯入

from concurrent.futures import ThreadPoolExecutor as tpe

import time

####初始化執行緒

tpe = tpe(10)

###列印指定資訊

# site : 列印的主題

# masg : 列印的資訊

def print_custom_masg(masg, site="", pyn='nothing', option='nothing'):

print('【brush:' + str(site) + '】【' + pyn + '】【' + option + '】: ' + str(masg))

 

tpe.submit(print_custom_masg,'1','2','3','4')

 

總結:

print_custom_masg: 為方法名

,'1','2','3','4' : 為 print_custom_masg 中的引數,和普通呼叫 print_custom_masg 方法傳參 類似