equal
deleted
inserted
replaced
120 name = repr(func) |
120 name = repr(func) |
121 return name |
121 return name |
122 |
122 |
123 class LoopTask(object): |
123 class LoopTask(object): |
124 """threaded task restarting itself once executed""" |
124 """threaded task restarting itself once executed""" |
125 def __init__(self, interval, func, args): |
125 def __init__(self, repo, interval, func, args): |
126 if interval <= 0: |
126 if interval <= 0: |
127 raise ValueError('Loop task interval must be > 0 ' |
127 raise ValueError('Loop task interval must be > 0 ' |
128 '(current value: %f for %s)' % \ |
128 '(current value: %f for %s)' % \ |
129 (interval, func_name(func))) |
129 (interval, func_name(func))) |
|
130 self.repo = repo |
130 self.interval = interval |
131 self.interval = interval |
131 def auto_restart_func(self=self, func=func, args=args): |
132 def auto_restart_func(self=self, func=func, args=args): |
132 restart = True |
133 restart = True |
133 try: |
134 try: |
134 func(*args) |
135 func(*args) |
137 logger.exception('Unhandled exception in LoopTask %s', self.name) |
138 logger.exception('Unhandled exception in LoopTask %s', self.name) |
138 raise |
139 raise |
139 except BaseException: |
140 except BaseException: |
140 restart = False |
141 restart = False |
141 finally: |
142 finally: |
142 if restart: |
143 if restart and not self.repo.shutting_down: |
143 self.start() |
144 self.start() |
144 self.func = auto_restart_func |
145 self.func = auto_restart_func |
145 self.name = func_name(func) |
146 self.name = func_name(func) |
146 |
147 |
147 def __str__(self): |
148 def __str__(self): |