在Python 3.7,Ubuntu 16.04中,Celery Task未注册异常
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Python 3.7,Ubuntu 16.04中,Celery Task未注册异常相关的知识,希望对你有一定的参考价值。
这就是芹菜配置的样子
from celery import Celery, group
celery = Celery('grouptest', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')
celery.conf.CELERY_TASK_SERIALIZER = 'pickle'
celery.conf.CELERY_RESULT_SERIALIZER ='pickle'
celery.conf.CELERY_ACCEPT_CONTENT = {'json', 'pickle'}
@celery.task
def add(self, x,y):
print('Executing with arguments', x, y)
return x+y
我用命令启动celery worker守护进程(在同一个工作目录中)
$celery worker -A grouptest -l info -c 5
在终端。
接下来,从另一个进程,我正在调用这样的服务。
bigList=[(randint(60, 90), randint(60, 90)) for _ in range(10)]
jobresult=group([add.s(celery, i[0], i[1]) for i in bigList]).apply_async()
#Basically adding a ten pairs of random numbers
有趣的是,即使经过漫长的等待,也只执行了一些任务。例如,jobresult[0].result
给出两个数字的总和就好了,但jobresult[1].result
说Task of kind 'grouptest.add' never registered, please make sure it's imported.
我甚至检查jobresult.ready()
是否在python REPL中设置了True
。有时它会在同一个REPL会话中抛出错误,有时却不会抛出错误。 (经过一些观察,我猜测,它从False
传递到错误到True
。)
我是celery的新手并且遵循一些模板,但是如何确保我正确地注册任务(无论这意味着什么)并且所有这些都是一致执行的。如果我的代码错了,至少错误会是一致的,是吗?
在撰写评论时,Celery不支持Python 3.7。您可以使用解决方法:https://github.com/celery/celery/issues/4500
以上是关于在Python 3.7,Ubuntu 16.04中,Celery Task未注册异常的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Ubuntu 16.04 上将 FTS5 扩展与带有 Python 3.7 的 sqlite3 python 模块一起使用?
Aosp代码repo时候需要python3.7,Ubuntu16.04下升级Python到3.7