主动开启进程
Posted blackball9
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了主动开启进程相关的知识,希望对你有一定的参考价值。
使用multiprocessing.Process来开启进程
import os import time from multiprocessing import Process def eat(): print(‘start eating‘,os.getpid()) time.sleep(1) print(‘end eating‘,os.getpid) def sleep(): print(‘start sleeping‘,os.getpid()) time.sleep(1) print(‘end sleeping‘,os.getpid()) if __name__ ==‘__main__‘: p1 = Process(target=eat)#创建一个即将要执行eat函数的进程对象 p1.start()#开启进程 p2 = Process(target=sleep)#开启一个即将要执行sleep函数的进程对象 p2.start()#开启进程 print(‘main:‘,os.getpid()) #我们打印后会发现每个进程都会有自己的进程id,我们主动开启了两个进程和一个main函数进程
以上是关于主动开启进程的主要内容,如果未能解决你的问题,请参考以下文章