1.开启子进程的两种方式: # 方式1: from multiprocessing import Process import time def task(name): print('%s is running'%(name)) time.sleep(2) print('%s is done'%name) if __name__ == '__main__': # p = Process(target=task,kwargs={'name':'子进程1'}) p = Process(target=…
一 进程创建的两种方式 from multiprocessing import Process import time def task(name): print(f'{name} is running') time.sleep(2) print(f'{name} is gone') if __name__ == '__main__': #在windows环境下, 开启进程必须在 __name__ == '__main__' 下面 p = Process(target=task,args=('常…
一.join控制子进程的一种方式 当主进程需要在子进程结束之后结束时,我们需要用到join来控制子进程. import time import random from multiprocessing import Process def func(index): time.sleep(random.random()) print('第%s个邮件已经发送完毕'%index) if __name__ == '__main__': p_list = [] for i in range(10): p =…