这是一个函数,没有返回值和其他的函数交互的方式
from concurrent.futures import ThreadPoolExecutor import time pool = ThreadPoolExecutor(50) def f1(): print('hello') time.sleep(1) for i in range(200): pool.submit(f1)
要是有函数参数的调用
from concurrent.futures import ThreadPoolExecutor import time # import random pool = ThreadPoolExecutor(50) def f1(i): print('hello') time.sleep(1) i+=1 return i def f2(i): i=i.result()#接受到的i是一个对象,所以要result一下 time.sleep(1) print(i) for i in range(200): #此处的i是f1的参数,把f1的返回值用于f2的时候需要使用函数的回调 pool.submit(f1,i).add_done_callback(f2)