我正在寻找一种在faust代理中运行非异步库的好方法:
@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),但似乎不起作用
发布于 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的答案。
请在开始长答案解决方案之前三思而后行。
https://stackoverflow.com/questions/62953747
复制相似问题