5

EDIT 1:

Actually, print statements outputs to the Celery terminal, instead of the terminal where the python program is ran - as @PatrickAllen indicated

OP

I've recently started to use Celery, but can't even get a simple test going where I print a line to the terminal after a 30 second wait.

In my tasks.py:

from celery import Celery

celery = Celery(__name__, broker='amqp://guest@localhost//', backend='amqp://guest@localhost//')

@celery.task
def test_message():
    print ("schedule task says hello")

in the main module for my package, I have:

import tasks.py


if __name__ == '__main__':
    <do something>
    tasks.test_message.apply_async(countdown=30)

I run it from terminal:

celery -A tasks worker --loglevel=info

Task is ran correctly, but nothing on the terminal of the main program. Celery output:

[2016-03-06 17:49:46,890: INFO/MainProcess] Received task: tasks.test_message[4282fa1a-8b2f-4fa2-82be-d8f90288b6e2] eta:[2016-03-06 06:50:16.785896+00:00]
[2016-03-06 17:50:17,890: WARNING/Worker-2] schedule task says hello
[2016-03-06 17:50:17,892: WARNING/Worker-2] The client is not currently connected.
[2016-03-06 17:50:18,076: INFO/MainProcess] Task tasks.test_message[4282fa1a-8b2f-4fa2-82be-d8f90288b6e2] succeeded in 0.18711688100120227s: None
snowbound
  • 1,692
  • 2
  • 21
  • 29
  • 1
    I think it has to do with async tasks not printing. If you return a value, you should see it in the celery output. If it is necessary to print, it may be a good idea to set up logging. – Patrick Allen Mar 06 '16 at 07:32
  • 2
    You're executing the task asynchronously, so you won't see the output. If you want to get the result, have the function return something and you can get the result. See [celery.result](http://celery.readthedocs.org/en/v2.2.5/reference/celery.result.html) docs. – antikantian Mar 06 '16 at 13:54
  • @antikantian how do you do that? when I try `result.BaseAsyncResult.result` in `def test():` nothing is returned on the console screen. – Florent Jan 19 '20 at 14:15

0 Answers0