def run(self):
# the code until the while statement does NOT run atomicaly
# a thread while loop cycle is atomic
# thread safe locals: L = threading.local(), then L.foo="baz"
django.setup()
self.logger.info('Worker Starts')
while not self._stopevent.isSet():
if not self.worker_queue.empty():
try:
task = self.worker_queue.get()
self.run_task(task)
except Exception as e:
helpers.save_task_failed(task,e)
else:
helpers.save_task_success(task)
self.worker_queue = None
self.logger.warn('Worker stopped, %s tasks handled'%self.tasks_counter)
评论列表
文章目录