mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-08-29 03:01:35 +00:00
Made code indentation to comply with PEP8
This commit is contained in:
@@ -4,34 +4,34 @@ import logging
|
||||
log = logging.getLogger("mysc.repeating_timer")
|
||||
|
||||
class RepeatingTimer(threading.Thread):
|
||||
"""Call a function after a specified number of seconds, it will then repeat again after the specified number of seconds
|
||||
Note: If the function provided takes time to execute, this time is NOT taken from the next wait period
|
||||
"""Call a function after a specified number of seconds, it will then repeat again after the specified number of seconds
|
||||
Note: If the function provided takes time to execute, this time is NOT taken from the next wait period
|
||||
|
||||
t = RepeatingTimer(30.0, f, args=[], kwargs={})
|
||||
t.start()
|
||||
t.cancel() # stop the timer's actions
|
||||
"""
|
||||
t = RepeatingTimer(30.0, f, args=[], kwargs={})
|
||||
t.start()
|
||||
t.cancel() # stop the timer's actions
|
||||
"""
|
||||
|
||||
def __init__(self, interval, function, daemon=True, *args, **kwargs):
|
||||
threading.Thread.__init__(self)
|
||||
self.daemon = daemon
|
||||
self.interval = float(interval)
|
||||
self.function = function
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
self.finished = threading.Event()
|
||||
def __init__(self, interval, function, daemon=True, *args, **kwargs):
|
||||
threading.Thread.__init__(self)
|
||||
self.daemon = daemon
|
||||
self.interval = float(interval)
|
||||
self.function = function
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
self.finished = threading.Event()
|
||||
|
||||
def cancel(self):
|
||||
"""Stop the timer if it hasn't finished yet"""
|
||||
log.debug("Stopping repeater for %s" % (self.function,))
|
||||
self.finished.set()
|
||||
stop = cancel
|
||||
def cancel(self):
|
||||
"""Stop the timer if it hasn't finished yet"""
|
||||
log.debug("Stopping repeater for %s" % (self.function,))
|
||||
self.finished.set()
|
||||
stop = cancel
|
||||
|
||||
def run(self):
|
||||
while not self.finished.is_set():
|
||||
self.finished.wait(self.interval)
|
||||
if not self.finished.is_set(): #In case someone has canceled while waiting
|
||||
try:
|
||||
self.function(*self.args, **self.kwargs)
|
||||
except:
|
||||
log.exception("Execution failed. Function: %r args: %r and kwargs: %r" % (self.function, self.args, self.kwargs))
|
||||
def run(self):
|
||||
while not self.finished.is_set():
|
||||
self.finished.wait(self.interval)
|
||||
if not self.finished.is_set(): #In case someone has canceled while waiting
|
||||
try:
|
||||
self.function(*self.args, **self.kwargs)
|
||||
except:
|
||||
log.exception("Execution failed. Function: %r args: %r and kwargs: %r" % (self.function, self.args, self.kwargs))
|
||||
|
Reference in New Issue
Block a user