| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- from threading import Timer,Thread,Event
- class RepeatTimer():
- def __init__(self,t:float,hFunction:callable):
- self.__deamon = True
- try:
- self.t=t
- self.hFunction = hFunction
- self.thread = Timer(self.t,self.handle_function)
- self.thread.daemon = self.__deamon
- except (KeyboardInterrupt, SystemExit):
- self.thread.cancel()
- self.thread.release()
- def handle_function(self):
- self.hFunction()
- try:
- self.thread = Timer(self.t,self.handle_function)
- self.thread.daemon = self.__deamon
- self.thread.start()
- except (KeyboardInterrupt, SystemExit):
- self.thread.cancel()
- self.thread.release()
- def start(self):
- self.thread.start()
- def cancel(self):
- self.thread.cancel()
- @property
- def function(self):
- return self.hFunction
- @function.setter
- def function(self,value:callable):
- self.hFunction = value
- @property
- def Interval(self):
- return self.thread.interval
- @Interval.setter
- def Interval(self, value:float):
- self.thread.interval = value
- @property
- def daemon(self):
- return self.thread.daemon
- @daemon.setter
- def daemon(self, value:bool):
- self.__deamon = value
- self.thread.daemon = value
- def setDaemon(self, value:bool):
- self.thread.setDaemon(value)
- @property
- def function(self):
- return self.thread.function
- @function.setter
- def function(self, value):
- self.thread.function = value
- @property
- def name(self):
- return self.thread.name
- @name.setter
- def name(self, value:str):
- #self.thread.name = value
- self.thread.setName(value)
- def setName(self,value:str):
- self.thread.setName(value)
|