from time import sleep
from multiprocessing import Process
import os
def run(str):
while True:
print("这是%s%s"%(str,os.getppid()))
sleep(1.2)
if __name__=="__main__":
print("进程开始")
p = Process(target=run, args=("子进程",))
p.start()
while True:
print("这是父进程")
sleep(1)
等待进程
from time import sleep
from multiprocessing import Process
import os
def run(str):
for i in range(10):
print("这是%s%s"%(str,os.getppid()))
sleep(1.2)
if __name__=="__main__":
print("进程开始")
p = Process(target=run, args=("子进程",))
p.start() #子进程开始
p.join() #等待子进程结束
print("父进程结束")