标签:close 开启 pen style target spl rom __name__ 两种
1创建进程的两种方式
# 开启子进程的方式一: ‘‘‘ from multiprocessing import Process import time def task(name): print(‘%s is running‘ %name) time.sleep(3) print(‘%s is done‘ %name) # 在windows系统上,开启子进程的操作必须放到if __name__ == ‘__main__‘的子代码中 if __name__ == ‘__main__‘: p=Process(target=task,args=(‘egon‘,)) #Process(target=task,kwargs={‘name‘:‘egon‘}) p.start() # 只是向操作系统发送了一个开启子进程的信号 print(‘主‘) ‘‘‘ # 开启子进程的方式二: from multiprocessing import Process import time class Myprocess(Process): def __init__(self,name): super().__init__() self.name=name def run(self): print(‘%s is running‘ %self.name) time.sleep(3) print(‘%s is done‘ %self.name) # 在windows系统上,开启子进程的操作必须放到if __name__ == ‘__main__‘的子代码中 if __name__ == ‘__main__‘: p=Myprocess(‘egon‘) p.start() # 只是向操作系统发送了一个开启子进程的信号 print(‘主‘)
2.join的用法
from multiprocessing import Process import time def task(name,n): print(‘%s is running‘ %name) time.sleep(n) print(‘%s is done‘ %name) if __name__ == ‘__main__‘:
标签:close 开启 pen style target spl rom __name__ 两种
原文地址:https://www.cnblogs.com/bigbox/p/12004586.html