入口参数与继承类

from multiprocessing import Process

def profun():
    print('子类没有重写时运行指定的入口函数')


# 穿件封装类继承process
class MyP(Process):
    pass
    #
    # # 重写run方法
    # def run(self):
    #     """
    #     该对象的入口函数
    #     :return:
    #     """
    #     print('执行被重写的方法作为入口函数')

# 程序入口
if __name__ == '__main__':
    # 创建实例,获得进程势力
    # p1 = MyP()
    # 进程开始运行
    # p1.start()
    # p2 = MyP(target=profun)
    # p2.start()
    p3 = MyP(target=profun)
    p3.start()

1.子类中重写了Process的方法,入口函数一定是run
2.子类中没有重写了Process的方法,入口函数一定是指定的target=profun

猜你喜欢

转载自blog.csdn.net/baidu_40450846/article/details/89108231
今日推荐