threading.Timer 返回值

定义
import  threading


class hy_Timer(threading.Timer):
    def __init__(self, interval, function, args=[], kwargs={}):
        self._original_function = function
        super(hy_Timer, self).__init__(
            interval, self._do_execute, args, kwargs)

    def _do_execute(self, *a, **kw):
        self.result = self._original_function(*a, **kw)

    def join(self):
        super(hy_Timer, self).join()
        return self.result

调用
t = hy_Timer(0.3, 函数名)
t.start()
print(t.join())

 

posted @ 2021-08-24 13:41  CodeYaSuo  阅读(275)  评论(0编辑  收藏  举报