From 48fe23b1f1980682489eaa37097be78c39c0e09c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 14 Jul 2015 09:09:29 +0200 Subject: [PATCH] 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. --- src/octoprint/util/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index 3b3d03a4..7d799fc2 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -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. 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``. + 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) if args is None: @@ -593,6 +594,7 @@ class RepeatedTimer(threading.Thread): self.kwargs = kwargs self.run_first = run_first self.condition = condition + self.daemon = daemon def cancel(self): self.finished.set()