關於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)

 

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