实际上,print
语句输出到Celery终端,而不是运行python程序的终端 - 正如@PatrickAllen指出的那样
我最近开始使用Celery,但是在30秒等待之后我甚至无法进行简单的测试。
在我的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")
在我的包的主模块中,我有:
import tasks.py
if __name__ == '__main__':
<do something>
tasks.test_message.apply_async(countdown=30)
我从终端运行它:
celery -A tasks worker --loglevel=info
任务正确运行,但主程序的终端没有任何内容。芹菜产量:
[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