code
import multiprocessing from multiprocessing import Pool import time import threading g_num = 0 def test1(): for i in range(10): time.sleep(1) print('test1',i) def test2(): for i in range(10): time.sleep(1) print('test2',i) if __name__ == '__main__': pool = Pool(2) # 允许进程池里同时放入2个进程 其他多余的进程处于挂起状态 pool.apply_async(test1) pool.apply_async(test2) pool.close() # close() 必须在join()前被调用 pool.join() # 进程池中进程执行完毕后再关闭,如果注释,那么程序直接关闭。 print("main")