[Python] Trying to import celery Instance from my app.py in tasks.py but getting error

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use celery instance that I have defined and initialized in app.py in control_plane.I am trying to use Celery that instance in tasks.py that resides in execution_plane. Below is my project structure. When I print celery instance in app.py I get the instance ID but when I try to print in my tasks.py I get none. Can you help me resolve the error.

    1. Control_plane 1.1 App.py <-- Celery app defined and initialized here
    2. Execution_plane 2.1 Tasks.py <---Trying to use celery_app.task here

    control_plane/app.py Debugging steps:

    if __name__ == '__main__':
    app = create_app() # Create the app instance
    # Initialize Celery
    celery_app = create_celery(app)
    print("Celery app initialized::::::::::::::::::", celery_app)
    app.run(debug=True)

    OUTPUT:
    Celery app initialized:::::::::::::::::: <Celery __main__ at 0x10aa892d0>

    Execution_plane/tasks.py

    from control_plane.app import celery_app as celery_app
    from celery.signals import task_prerun, task_postrun
    from control_plane.extensions import db

    # Initialize Celery
    # celery_app = create_celery(flask_app)

    print("Celery app initialized::::::::::::::::::", celery_app)


    Error I get: Celery app initialized:::::::::::::::::: None

    Continue reading...

Compartilhe esta Página