cat custommulti.py
from multiprocessing import Process
import sys
class MyProcess(Process):
def __init__(self,name):
super(MyProcess,self).__init__()
self.name=name
def run(self):
n=1
while True:
n+=1
print('自定义进程:{},n的值:{}'.format(self.name,n))
if n == 10:
break
if __name__ == '__main__':
p1=MyProcess('进程1')
p2=MyProcess('进程2')
p1.start()
p2.start()
[root@ceph01 python]
自定义进程:进程1,n的值:2
自定义进程:进程1,n的值:3
自定义进程:进程1,n的值:4
自定义进程:进程1,n的值:5
自定义进程:进程1,n的值:6
自定义进程:进程1,n的值:7
自定义进程:进程1,n的值:8
自定义进程:进程2,n的值:2
自定义进程:进程2,n的值:3
自定义进程:进程1,n的值:9
自定义进程:进程1,n的值:10
自定义进程:进程2,n的值:4
自定义进程:进程2,n的值:5
自定义进程:进程2,n的值:6
自定义进程:进程2,n的值:7
自定义进程:进程2,n的值:8
自定义进程:进程2,n的值:9
自定义进程:进程2,n的值:10