summaryrefslogtreecommitdiff
path: root/python/skytools/scripting.py
diff options
context:
space:
mode:
authormartinko2012-08-03 11:08:50 +0000
committermartinko2012-08-03 11:08:50 +0000
commitd702d0c7e9573e1455f66e6c62ace6d1ab77705b (patch)
tree3d7d8d7fcecd76b3dbc2e3f4b99b273cb575b5f0 /python/skytools/scripting.py
parent51c5f2f98b626eda2e564dd81faec563d45dd1e0 (diff)
skytools.scripting: added shutdown() to BaseScript
This should be used for cleanup code instead of abusing stop(), which is called from signal handler.
Diffstat (limited to 'python/skytools/scripting.py')
-rw-r--r--python/skytools/scripting.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/python/skytools/scripting.py b/python/skytools/scripting.py
index 61b4aa6a..7bb98a19 100644
--- a/python/skytools/scripting.py
+++ b/python/skytools/scripting.py
@@ -510,6 +510,9 @@ class BaseScript(object):
else:
break
+ # run shutdown, safely?
+ self.shutdown()
+
def run_once(self):
state = self.run_func_safely(self.work, True)
@@ -597,6 +600,14 @@ class BaseScript(object):
if hasattr(signal, 'SIGINT'):
signal.signal(signal.SIGINT, self.hook_sigint)
+ def shutdown(self):
+ """Will be called just after exiting main loop.
+
+ In case of daemon, if will be called in same process as work(),
+ unlike __init__().
+ """
+ pass
+
# define some aliases (short-cuts / backward compatibility cruft)
stat_add = stat_put # Old, deprecated function.
stat_inc = stat_increase