【发布时间】:2020-09-30 15:57:46
【问题描述】:
基本上我有类似这样的同步代码:
def f(.):
...
def call(.):
..Some sync code..
try:
resp = f(..)
...some more transformations of resp...
return ..
except:
..Some error handling..
async def af(.):
...
基本上我想动态更改call 的代码,以便它可以调用和等待af 函数而不是f。有没有解决的办法?我在 github 上找到了syncit,但这似乎不是我的解决方案,因为您必须先将代码重写为异步,然后再将其降级为同步。任何帮助将不胜感激。
【问题讨论】:
-
看看
triotrio.readthedocs.io/en/latest/tutorial.html。请注意,在第一个表中,常规同步函数不能调用异步函数。但是,trio.run()提供了一种方法来执行此操作。
标签: python python-asyncio