python 芹菜+redis实践遇到的问题

1.问题一: Unrecoverable error: AttributeError("'str' object has no attribute 'items'",)

原因redis芹菜兼容版本,bug未修复高版本问题:

解决方案,redis降级:pip install redis==2.10.6

2.问题2:

from kombu.async.timer import Entry, Timer as Schedule, to_timestamp, logger
^
SyntaxError: invalid syntax

原因,celery目前3.7python还未支持

 

 编写tasks.py :

# coding=utf-8
import time
import json
from celery import Celery

celery = Celery('tasks', broker='redis://172.20.10.2:6379/0')
# 如果有redis密码
# celery = Celery('tasks', broker='redis://:foobared@localhost:6379/0')

@celery.task
def celery_demo(args):
print("this is test async demo")
return {"hello":"{} that's result async".format(args)}

启动芹菜celery: celery -A  tasks    worker --loglevel=info

开始终端调用:demo

 

 结果查看

 

posted @ 2020-04-13 17:34  不带R的墨菲特  阅读(359)  评论(0编辑  收藏  举报