Mercurial > templog
changeset 456:3db3665af2e2
reload config on SIGHUP
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 03 Jan 2013 20:12:07 +0800 |
parents | e12d6d677320 |
children | 176fc5b68a3f 94932e7051e5 |
files | py/params.py py/tempserver.py |
diffstat | 2 files changed, 21 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/py/params.py Thu Jan 03 20:11:54 2013 +0800 +++ b/py/params.py Thu Jan 03 20:12:07 2013 +0800 @@ -1,6 +1,10 @@ # -*- coding: utf-8 -*- import collections import json +import signal + +import gevent + import config from utils import W,L,E,EX @@ -17,6 +21,7 @@ def __init__(self): self.update(_FIELD_DEFAULTS) + gevent.signal(signal.SIGHUP, self.reload_signal) def __getattr__(self, k): return self[k] @@ -33,7 +38,11 @@ except IOError, e: W("Missing parameter file, using defaults. %s", e) return - u = json.load(f) + try: + u = json.load(f) + except Exception, e: + raise self.Error(e) + for k in u: if k not in self: raise self.Error("Unknown parameter %s=%s in file '%s'" % (str(k), str(u[k]), getattr(f, 'name', '???'))) @@ -45,3 +54,10 @@ json.dump(self, f, sort_keys=True, indent=4) f.write('\n') f.flush() + + def reload_signal(self): + try: + self.load() + L("Reloaded params") + except self.Error, e: + W("Problem reloading: %s" % str(e))