From b2b3459fa2d7f5a900851a44a6c04c0d56949949 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 3 Mar 2013 11:16:00 +0000 Subject: [PATCH] fix reload worker and readd watch after reload to not only work for one change --- pandora/app/config.py | 27 ++++++++++++++++++++------- pandora/settings.py | 2 ++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/pandora/app/config.py b/pandora/app/config.py index 00fe9d45d..f414a5c54 100644 --- a/pandora/app/config.py +++ b/pandora/app/config.py @@ -98,7 +98,10 @@ check the README for further details. except: pass + + def reloader_thread(): + settings.RELOADER_RUNNING=True _config_mtime = 0 try: import pyinotify @@ -106,11 +109,20 @@ def reloader_thread(): except: INOTIFY = False if INOTIFY: - wm = pyinotify.WatchManager() - name = os.path.realpath(settings.SITE_CONFIG) - wm.add_watch(name, pyinotify.IN_CLOSE_WRITE, lambda event: load_config()) - notifier = pyinotify.Notifier(wm) - notifier.loop() + class ConfigChanges: + def __init__(self): + name = os.path.realpath(settings.SITE_CONFIG) + self.name = name + self.wm = pyinotify.WatchManager() + self.reload_config() + notifier = pyinotify.Notifier(self.wm) + notifier.loop() + + def reload_config(self): + load_config() + self.wm.add_watch(self.name, pyinotify.IN_CLOSE_WRITE, + lambda event: self.reload_config()) + ConfigChanges() else: while RUN_RELOADER: try: @@ -205,5 +217,6 @@ def update_geoip(force=False): os.system('gunzip "%s.gz"' % path) def init(): - load_config() - thread.start_new_thread(reloader_thread, ()) + if not settings.RELOADER_RUNNING: + load_config() + thread.start_new_thread(reloader_thread, ()) diff --git a/pandora/settings.py b/pandora/settings.py index 4a684ee0b..ca39eb5d3 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -206,6 +206,8 @@ LIST_ICON = join(SCRIPT_ROOT, 'list_icon.py') DB_GIN_TRGM = False + +RELOADER_RUNNING = False #you can ignore things below this line #=========================================================================