我在aiohttp应用程序中有一个控制器操作。
async def handler_message(request):
try:
content = await request.json()
perform_message(x,y,z)
except (RuntimeError):
print("error in perform fb message")
finally:
return web.Response(text="Done")
perform_message
是一个异步函数。当我调用这个函数时,我希望我的动作尽快返回,并将 perform_message
放入事件循环中。
这样一来,perform_message
就不会被立即执行。
loop.run_until_complete(coro)
或者loop.run_forever()
来启动循环。参见:https://docs.python.org/zh-cn/3/library/asyncio-eventloop.html#running-and-stopping-the-loop 在你的情况下,似乎你正在寻找第一种选项。 - freakish