Python 進程池

from multiprocessing import Pool,freeze_support

def run(x):
    print(x*x)

if __name__ == '__main__':
    freeze_support()
    thread = Pool(processes=4) #初始化進程池Thread Pool
    for i in range(0,50):
        thread.apply_async(run,(i,)) #加入任務
    thread.close() #關閉進程池
    thread.join() #等待進程池內任務執行完畢