, , Timer , / Python 2 threading.py:
>>> from threading import Timer
>>> type(Timer)
<type 'function'>
_Timer. , ; init , target, args, kwargs interval .
, CustomTimer:
from threading import _Timer
class CustomTimer(_Timer):
def __init__(self, interval, function, args=[], kwargs={}):
self._original_function = function
super(CustomTimer, 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(CustomTimer, self).join()
return self.result
:
def add_together(a, b):
return a + b
c = CustomTimer(1, add_together, (2, 4))
c.start()
print c.join()
6 1 .