我正在尝试使用 asyncio 异步调用 REST API,但我不断收到错误“coroutine was never waitinged
”,我明白。但我想要这种行为,我希望我的函数通过发布而不是等待结果来结束。这是我的代码
async def callCoroutine:
#call a REST API
def lambda_handler(event, context):
loop = asyncio.get_event_loop()
task = loop.create_task(callCoroutine(data))
return
有人可以帮忙吗?
最佳答案
如果只需要调用API,不考虑结果,可以在另一个线程中使用Executor,不会阻塞主线程。
要在执行器中运行,请使用 AbstractEventLoop.run_in_executor()与 concurrent.futures 的执行者.
关于python asyncio REST api 调用给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51674786/