Python程序池的使用
阿新 • • 發佈:2019-02-05
#!/usr/bin/evn python
# -*- coding:utf-8 -*-
import multiprocessing
import time
import threading
from multiprocessing import Pool,Array,Value,Queue
def simonPoolTest(name,action):
print("你傳入進來的是:"+name+",操作是:"+action)
time.sleep(10)
if __name__=="__main__":
# python的程序池的使用
pool = multiprocessing.Pool();
for i in range(0,10):
"""
從程序池中拿到一個程序後,直接使用apply_async的方法新增程序需
要執行的操作以及操作方法的引數
"""
pool.apply_async(simonPoolTest, args=("simon", "新增"))
"""
程序使用完後,需要通過使用close方法把程序的資源釋放出來
"""
pool.close();
"""
在使用執行緒池的時候,必須先close,再進行join()
如果join(2)是表示 ,最多等2秒
"""
pool.join();