Process
使用Process创建子进程
通过Process子类创建子进程
子类重写run方法就可以替代target
from multiprocessing import Process
import time
class MyProcess(Process):
def run(self):
while True:
print('---test---')
time.sleep(1)
p1 = MyProcess()
p1.start()
while True:
print('---main---')
time.sleep(1)
运行结果
root@iZ947mgy3c5Z:/tmp# python3 multi_7.py
---main---
---test---
---main---
---test---
---main---
---test---