python的多进程

实现代码如下:

#多进程
import time
import  multiprocessing
class test:
    def test1(self,a):
        for i in range(3):
            print(a)
            time.sleep(1)
    def test2(self,b):
        for i in range(3):
            print(b)
            time.sleep(1)
if __name__ == '__main__':
    t1=multiprocessing.Process(target=test().test1,args=(1,))
    t2=multiprocessing.Process(target=test().test2, args=(2,))
    #开启线程
    t1.start()
    t2.start()
    #阻塞线程,等待t1进程结束,再执行下面的代码
    t1.join()
    print('3')

你可能感兴趣的:(python的多进程)