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

 结果查看

原文地址:https://www.cnblogs.com/SunshineKimi/p/12692752.html