定义
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())