Python+Celery:忽略每次调用的任务结果?
是否可以在每次调用的基础上忽略任务结果?
例如,这样我可以在 Web 请求期间运行任务时忽略任务的结果,但在交互运行任务时等待结果(可能有调试信息)?
我知道任务具有 ignore_result
标志,但我特别想知道是否可以在每次调用的基础上(而不是“全局”基础)设置 ignore_result
。
Is it possible to ignore task results on a per-invocation basis?
For example, so I can ignore the results of tasks when they are being run during a web request, but wait for the result (which might have, eg, debug info) when I'm running the task interactively?
I know that Tasks have the ignore_result
flag, but I'm wondering specifically if it's possible to set ignore_result
on a per-invocation basis (not a "global" basis).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常不会,因为ignore_result是只有工作人员使用的任务的属性(以决定是否发回结果)。
但是,如果您使用自己的任务参数(避免将其称为ignore_result),并让任务根据该参数设置其ignore_result,则可以做到这一点:
Not normally, because ignore_result is a property of a Task that only the workers use (to decide whether to send a result back).
But you could do it if you used your own task parameter (avoid calling it ignore_result), and have the task set its ignore_result based on that:
您可以在调用
apply_async
或delay
时使用ignore_result=True/False
您可能会遇到 如果您运行的是旧版本的 celery,则会出现此 错误。您可以阅读有关如何更详细地使用
ignore_result
的文档 此处You can use
ignore_result=True/False
while callingapply_async
ordelay
You might run into this error if you are running an older version of celery. You can read the docs about how to use
ignore_result
in more detail here