首頁  >  問答  >  主體

python - make_celery 构造函数中的 abstract=True 的作用?

代码: celery 构造函数,在celery中加载flask的app context:

def make_celery(app):
    celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
    celery.conf.update(app.config)
    TaskBase = celery.Task
    class ContextTask(TaskBase):
        abstract = True
        def __call__(self, *args, **kwargs):
            with app.app_context():
                return TaskBase.__call__(self, *args, **kwargs)
    celery.Task = ContextTask
    return celery

请问,这里的abstract=True的作用是? 谢谢各位!

阿神阿神2740 天前814

全部回覆(1)我來回復

  • 黄舟

    黄舟2017-04-18 09:27:34

    建議直接看源碼,一般源碼中有註解:
    celery/app/task.py:

    #: If :const:`True` the task is an abstract base class.
    abstract = True

    回覆
    0
  • 取消回覆