worker.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:django-queue 作者: Aviah 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号