hi,all
背景
最近在一个tornado项目里面,用了celery做队列,因为底层存储是mysql,所以想到用celery来把耗时的请求交给它做。celery配置的broker是rabbitmq,然后搭配tornado-celery库来进行调用。
问题
我看了下网上关于
tornado-celery
的教程,在ubuntu和mac os上面跑了下面这个例子,两个地方用的库的版本基本是一致的,但是osx那边的调用一直不成功,调用下面例子的
curl http://localhost/sleep
命令,请求就卡死在那里了。
例子如下
task.py
#!/usr/bin/env python
# encoding: utf-8
import time
from celery import Celery
C_FORCE_ROOT=True
celery = Celery("tasks", broker="amqp://guest:guest@localhost:5672")
celery.conf.CELERY_RESULT_BACKEND = "amqp"
@celery.task
def sleep(seconds):
time.sleep(float(seconds))
return seconds
if __name__ == "__main__":
celery.start()
server.py