python – Celery到期 – 上升异常
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – Celery到期 – 上升异常,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2022字,纯文字阅读大概需要3分钟。
内容图文
在docs link中关于到期
# Task expires after one minute from now.
add.apply_async(args=[10, 10], expires=60)
我用:
from tasks import add
result = add.apply_async(args=[10, 10], expires=6000)
printus(result)
def printus(result):
print (result) #task id
print (result.ready()) # returns True if the task has finished processing.
print (result.result) # task is not ready, so no return value yet.
print (result.get()) # Waits until the task is done and returns the retval.
print (result.result) # direct access to result, doesn't re-raise errors.
print (result.successful()) # returns True if the task didn't end in failure.)
tasks.py
from celery.task import task
@task
def add(x, y):
return x + y
在celeryd:
[2012-03-21 19:50:03,012: WARNING/MainProcess] Skipping revoked task: tasks.add[4ffcff91-b12b-4bce-8d47-159314759859]
在控制台中:
4ffcff91-b12b-4bce-8d47-159314759859
True
Traceback (most recent call last):
File "/home/echeg/Dropbox/my_py/opoveshun/tests/celery/run_task.py", line 53, in <module>
tr.countdown()
File "/home/echeg/Dropbox/my_py/opoveshun/tests/celery/run_task.py", line 26, in countdown
self.printus(result)
File "/home/echeg/Dropbox/my_py/opoveshun/tests/celery/run_task.py", line 48, in printus
print (result.get()) # Waits until the task is done and returns the retval.
File "/usr/local/lib/python2.7/dist-packages/celery/result.py", line 95, in get
interval=interval)
File "/usr/local/lib/python2.7/dist-packages/celery/backends/amqp.py", line 144, in wait_for
raise self.exception_to_python(meta["result"])
celery.exceptions.TaskRevokedError
为什么我会得到例外?结果尚未过期
如果我使用:
result = add.apply_async(args=[10, 10])
一切都好
226107de-f739-4860-83bc-d843f17a257e
False
None
20
20
True
解决方法:
celeryd认为你的任务已经过期:
[2012-03-21 19:50:03,012: WARNING/MainProcess] Skipping revoked task: tasks.add[4ffcff91-b12b-4bce-8d47-159314759859]
当一个工人拿起过期的任务时,it revokes it没有执行.检查您的时区设置?我遇到了相反的问题:任务到期时没有到期.这为我修好了:
CELERY_ENABLE_UTC = True
CELERY_TIMEZONE = 'Etc/UTC'
内容总结
以上是互联网集市为您收集整理的python – Celery到期 – 上升异常全部内容,希望文章能够帮你解决python – Celery到期 – 上升异常所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。