try to avoid thread exceptions on shutdown

This commit is contained in:
j 2013-07-13 14:46:48 +00:00
parent f0b8824f62
commit d636f63f65
2 changed files with 15 additions and 0 deletions

View file

@ -21,6 +21,7 @@ from archive.extract import supported_formats, AVCONV
_win = (sys.platform == "win32") _win = (sys.platform == "win32")
RUN_RELOADER = True RUN_RELOADER = True
NOTIFIER = None
def get_version(): def get_version():
info = os.path.join(os.path.dirname(__file__), '..', '..', '.bzr/branch/last-revision') info = os.path.join(os.path.dirname(__file__), '..', '..', '.bzr/branch/last-revision')
@ -130,6 +131,7 @@ check the README for further details.
def reloader_thread(): def reloader_thread():
global NOTIFIER
settings.RELOADER_RUNNING=True settings.RELOADER_RUNNING=True
_config_mtime = 0 _config_mtime = 0
try: try:
@ -149,6 +151,7 @@ def reloader_thread():
wm = pyinotify.WatchManager() wm = pyinotify.WatchManager()
add_watch() add_watch()
notifier = pyinotify.Notifier(wm) notifier = pyinotify.Notifier(wm)
NOTIFIER = notifier
notifier.loop() notifier.loop()
else: else:
while RUN_RELOADER: while RUN_RELOADER:
@ -271,3 +274,13 @@ def init():
if not settings.RELOADER_RUNNING: if not settings.RELOADER_RUNNING:
load_config() load_config()
thread.start_new_thread(reloader_thread, ()) thread.start_new_thread(reloader_thread, ())
def shutdown():
if settings.RELOADER_RUNNING:
RUN_RELOADER = False
settings.RELOADER_RUNNING = False
if NOTIFIER:
NOTIFIER.stop()

View file

@ -23,3 +23,5 @@ if __name__ == "__main__":
sys.stderr.write("Error: Can't find '%s'.\nBefore you run pan.do/ra you must create it\n" % settings.SITE_CONFIG) sys.stderr.write("Error: Can't find '%s'.\nBefore you run pan.do/ra you must create it\n" % settings.SITE_CONFIG)
sys.exit(1) sys.exit(1)
execute_manager(settings) execute_manager(settings)
import app.config
app.config.shutdown()