关于Python的func_timeout方法超时库务必要注意一个细节【内部func调用父类方法super必须携带参数,否则会报错】

 

super().aa(a, b) 和  super(Test001, self).aa(a, b)默认是等价的

 

from app.libs.timeout.own_func_timeout import OwnFuncTimeout


class Test:
    def aa(self, a, b):
        while True:
            print(a, b)


class Test001(Test):
    def aa(self, a, b):
        """
            功能:重写父类方法
            特殊说明:
                1、虽然说super().aa(a, b) 和  super(Test001, self).aa(a, b) 是等价的
                2、但是在func_timeout方法内部,则必须使用super(Test001, self).aa(a, b),否则会报错!
        """
        OwnFuncTimeout.func_timeout(2, lambda: super(Test001, self).aa(a, b))


Test001().aa(1, 2)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章