本文介绍了可以或如何在Google Cloud Functions上使用Python asyncio?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在Google Cloud Functions上使用Python的asyncio
?
Is it possible to use Python's asyncio
on Google Cloud Functions?
async def handle_someting():
# do something
some = await aiofunc()
# Do I need the code below?
loop = asyncio.get_event_loop()
loop.run_until_complete(handle_someting())
loop.close()
推荐答案
当然,您只需要从主要部署的函数运行异步函数即可(在这里,您将部署test
函数):
Sure, you just need to run the async functions from your main deployed function (here, you would deploy the test
function):
import asyncio
async def foo():
return 'Asynchronicity!'
async def bar():
return await foo()
def test(request):
return asyncio.run(bar())
这篇关于可以或如何在Google Cloud Functions上使用Python asyncio?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!