Flask, blueprints uses celery task and got cycle import

What I do to solve this error is that I create two Flask instance which one is for Web app, and another is for initial Celery instance.

Like @Miguel said, I have

  • celery_app.py for celery instance
  • manager.py for Flask instance

And in these two files, each module has it's own Flask instance.

So I can use celery.task in Views. And I can start celery worker separately.


I don't have the code to try this out, but I think things would work better if you move the creation of the Celery instance out of tasks.py and into the create_app function, so that it happens at the same time the app instance is created.

The argument you give to the Celery worker in the -A option does not need to have the tasks, Celery just needs the celery object, so for example, you could create a separate starter script, say celery_worker.py that calls create_app to create app and cel and then give it to the worker as -A celery_worker.cel, without involving the blueprint at all.

Hope this helps.