标签:rom 逻辑 print filename walk import join() main tip
from multiprocessing import Process
import time
def func(arg1,arg2):
print('*'*arg1)
time.sleep(5)
print('*'*arg2)
if __name__ == '__main__': #windos必须声明
p = Process(target=func, args=(10,20))
p.start()
print('hahaha')
#需求,要求子进程结束后立即执行主进程
p.join()#join()方法用于感知一个子进程的结束,类似将异步的程序改为同步
print('========:运行完了')
>>>>
hahaha
**********
********************
========:运行完了
from multiprocessing import Process
import time
def func(arg1,arg2):
print('*'*arg1)
time.sleep(5)
print('*'*arg2)
if __name__ == '__main__': #windos必须声明
p_lst = []
for i in range(10):
p = Process(target=func, args=(10*i,20*i))
p_lst.append(p)
p.start() #子进程还是异步执行
[p.join() for p in p_lst]#join()每个子进程,保证所有的子进程都结束了才执行下面这句
print('运行完了')
import os
from multiprocessing import Process
def func(filename, content):
with open(filename,'w') as f:
f.write(content*10*'*')
if __name__ == '__main__':
p_lst = []
for i in range(5):
p = Process(target=func, args=('info%s'%i,i))
p_lst.append(p)
p.start()
[p.join() for p in p_lst]
print([i for i in os.walk(r'C:\Demo')])
标签:rom 逻辑 print filename walk import join() main tip
原文地址:https://www.cnblogs.com/konglinqingfeng/p/9685402.html