[Python] Why is my Celery task stuck in RECEIVED state?

Discussão em 'Python' iniciado por Stack, Fevereiro 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm going through Celery tutorial and I'm trying to use the "hello world" example:

    from celery import Celery
    from celery.utils.log import get_task_logger

    app = Celery("src.my_module.tasks",
    broker="amqp://guest:guest@localhost:5672/",
    backend="redis://localhost:6379/0")

    logger = get_task_logger(__name__)


    @app.task
    def add(x, y):
    logger.info("Running add function with: %s, %s", x, y)
    return x + y


    I start Celery worker and Flower ui in powershell:

    celery -A src.my_module.tasks worker --loglevel=info

    celery -A src.my_module.tasks flower --loglevel=info

    And btw. these are the docker container definitions for the brocker and result backend:

    rabbitmq:
    image: rabbitmq:3-management
    environment:
    RABBITMQ_DEFAULT_USER: guest
    RABBITMQ_DEFAULT_PASS: guest
    ports:
    - "5672:5672"
    - "15672:15672"

    redis:
    image: redis:alpine
    restart: always
    ports:
    - "6379:6379"


    Then I open up python console, import the add function and run: add.delay(1, 2). The terminal window in which I run Celery shows some output:

    [2025-02-11 20:20:17,815: INFO/MainProcess] Task src.my_module.tasks.add[598610d9-3275-4996-bc81-065546677ae4] received

    Aaaaand... That's it. The task never finishes, never even leaves the RECEIVED state. When I inspect it in Flower, I can see the arg, that status and result property which is None. Broker backend doesn't matter - both redis and rabbitmq say that the messages are unacked.

    Continue reading...

Compartilhe esta Página