本文介绍了如何将Celery与asyncio结合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个使celery任务看起来像asyncio.Task的包装器?还是有更好的方法将Celery与asyncio集成?

How can I create a wrapper that makes celery tasks look like asyncio.Task? Or is there a better way to integrate Celery with asyncio?

@asksol 说::

但是我找不到任何专门针对asyncio框架的代码示例.

But I could not find any code examples specifically for asyncio framework.

推荐答案

如官方网站中所述,这可以从Celery 5.0版中实现:

That will be possible from Celery version 5.0 as stated in the official site:

http://docs.celeryproject.org/en/4.0/whatsnew-4.0.html#preface

  1. 如果我们计划利用新的asyncio库,则Celery的下一个主要版本将仅支持Python 3.5.
  2. 删除对Python 2的支持将使我们能够删除大量的兼容性代码,而与Python 3.5一起使用使我们能够利用键入,异步/等待,异步和类似概念的优势,在较早的版本中别无选择./li>
  1. The next major version of Celery will support Python 3.5 only, were we are planning to take advantage of the new asyncio library.
  2. Dropping support for Python 2 will enable us to remove massive amounts of compatibility code, and going with Python 3.5 allows us to take advantage of typing, async/await, asyncio, and similar concepts there’s no alternative for in older versions.

以上内容来自上一个链接.

所以最好的办法是等待发布 5.0版

So the best thing to do is wait for version 5.0 to be distributed!

与此同时,祝您编码愉快:)

In the mean time, happy coding :)

这篇关于如何将Celery与asyncio结合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:22