1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import time
- import threading
- from concurrent.futures import ThreadPoolExecutor
- # method对应于:自行编写的方法,可传参(可传多个参数,形如pool.submit(self.method, a,b))
- def method1():
- print("我是方法1")
- return 1
- def method2():
- print("我是方法2")
- return 2
- def method3():
- print("我是方法3")
- return 3
- def method4():
- print("我是方法4")
- return 4
- def method5():
- print("我是方法5")
- return 5
- def fun():
- start = time.time()
- # 创建包含5个线程的线程池
- pool = ThreadPoolExecutor(max_workers=5)
- future1 = pool.submit(method1)
- future2 = pool.submit(method2)
- future3 = pool.submit(method3)
- future4 = pool.submit(method4)
- future5 = pool.submit(method5)
|