Home  >  Q&A  >  body text

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的作用是? 谢谢各位!

阿神阿神2646 days ago756

reply all(1)I'll reply

  • 黄舟

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

    建议直接看源码,一般源码中有注释:
    celery/app/task.py:

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

    reply
    0
  • Cancelreply