如何将Celery与asyncio结合? [英] How to combine Celery with asyncio?

查看:294
本文介绍了如何将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 说::

使用Celery作为异步I/O框架之上的分布式层是很常见的(提示:将CPU绑定的任务路由到prefork工作者意味着它们不会阻塞事件循环).

It's quite common to use Celery as a distributed layer on top of async I/O frameworks (top tip: routing CPU-bound tasks to a prefork worker means they will not block your event loop).

但是我找不到任何专门针对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结合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆