Stop RepeatedTimers on server shutdown by default
daemon flag was missing, leading to the timer staying active even when a shutdown was triggered. Added new daemon flag to timer constructor, defaulting to true, that fixes that behaviour.
This commit is contained in:
parent
75992ef837
commit
48fe23b1f1
1 changed files with 3 additions and 1 deletions
|
|
@ -570,9 +570,10 @@ class RepeatedTimer(threading.Thread):
|
||||||
run_first (boolean): If set to True, the function will be run for the first time *before* the first wait period.
|
run_first (boolean): If set to True, the function will be run for the first time *before* the first wait period.
|
||||||
If set to False (the default), the function will be run for the first time *after* the first wait period.
|
If set to False (the default), the function will be run for the first time *after* the first wait period.
|
||||||
condition (callable): Condition that needs to be True for loop to continue. Defaults to ``lambda: True``.
|
condition (callable): Condition that needs to be True for loop to continue. Defaults to ``lambda: True``.
|
||||||
|
daemon (bool): daemon flag to set on underlying thread.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, interval, function, args=None, kwargs=None, run_first=False, condition=None):
|
def __init__(self, interval, function, args=None, kwargs=None, run_first=False, condition=None, daemon=True):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
if args is None:
|
if args is None:
|
||||||
|
|
@ -593,6 +594,7 @@ class RepeatedTimer(threading.Thread):
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
self.run_first = run_first
|
self.run_first = run_first
|
||||||
self.condition = condition
|
self.condition = condition
|
||||||
|
self.daemon = daemon
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
self.finished.set()
|
self.finished.set()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue