首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Faust Python阻塞函数

Faust Python阻塞函数
EN

Stack Overflow用户
提问于 2020-07-17 20:14:33
回答 1查看 129关注 0票数 0

我正在寻找一种在faust代理中运行非异步库的好方法:

代码语言:javascript
复制
@app.agent(topic)
async def cp_agent(cp_stream):
    async for batch in cp_stream.take(100, within=5):
        print("------ Indexing a CPE  BATCH -----")
        [... Here Use of A NONE Async Function like elastic-dsl]

我读了Adding Faust to your Existing Architecture的帖子,我推断我们只需要在faust中使用IO/Async库。现在有办法在faust中创建一个非异步库吗?我看到一些猴子在修补:(gevent和eventlet),但似乎不起作用

EN

回答 1

Stack Overflow用户

发布于 2020-09-20 04:09:55

Short answer:不,你不能在faust中使用阻塞库。在官方的python库中使用async/await support或者像aioelasticsearch这样有用的东西。

Logn answer:是的,你可以,它很容易上手,但是

深入研究此How to use asyncio with existing blocking library?以找到解决方案。但首先要仔细阅读这个asyncio, wrapping a normal function as asynchronous的答案。

请在开始长答案解决方案之前三思而后行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62953747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档