可以或如何在Google Cloud Functions上使用Python asyncio?


问题内容

是否可以asyncio在Google Cloud Functions上使用Python ?

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功能):

import asyncio

async def foo():
    return 'Asynchronicity!'

async def bar():
    return await foo()

def test(request):
    return asyncio.run(bar())