# HG changeset patch # User Sylvain Thénault # Date 1316678545 -7200 # Node ID 5f145462e0414d5c98974997aebb6b786ecac398 # Parent ce8a4de2ecf1c145b8506ec0e83c9bfac625ab27 [repo] ensure we don't restart a task while the repo is shutting down (closes #1942736) we need a safety belt in cw itself again looping task which use 'try / except' or doesn't need to access the db (which will trigger ShuttingDown exception) diff -r ce8a4de2ecf1 -r 5f145462e041 server/repository.py --- a/server/repository.py Thu Sep 22 10:02:17 2011 +0200 +++ b/server/repository.py Thu Sep 22 10:02:25 2011 +0200 @@ -344,7 +344,7 @@ self.looping_task(cleanup_session_interval, self.clean_sessions) assert isinstance(self._looping_tasks, list), 'already started' for i, (interval, func, args) in enumerate(self._looping_tasks): - self._looping_tasks[i] = task = utils.LoopTask(interval, func, args) + self._looping_tasks[i] = task = utils.LoopTask(self, interval, func, args) self.info('starting task %s with interval %.2fs', task.name, interval) task.start() diff -r ce8a4de2ecf1 -r 5f145462e041 server/utils.py --- a/server/utils.py Thu Sep 22 10:02:17 2011 +0200 +++ b/server/utils.py Thu Sep 22 10:02:25 2011 +0200 @@ -122,11 +122,12 @@ class LoopTask(object): """threaded task restarting itself once executed""" - def __init__(self, interval, func, args): + def __init__(self, repo, interval, func, args): if interval <= 0: raise ValueError('Loop task interval must be > 0 ' '(current value: %f for %s)' % \ (interval, func_name(func))) + self.repo = repo self.interval = interval def auto_restart_func(self=self, func=func, args=args): restart = True @@ -139,7 +140,7 @@ except BaseException: restart = False finally: - if restart: + if restart and not self.repo.shutting_down: self.start() self.func = auto_restart_func self.name = func_name(func)