可以或如何在Google云函数上使用Python asyncio?

2024-09-27 07:31:03 发布

您现在位置:Python中文网/ 问答频道 /正文

是否可以在Google云函数上使用Python的asyncio?在

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()

Tags: 函数loopasyncioasyncdefgooglesomeawait
1条回答
网友
1楼 · 发布于 2024-09-27 07:31:03

当然,您只需要从主部署函数运行异步函数(在这里,您将部署test函数):

import asyncio

async def foo():
    return 'Asynchronicity!'

async def bar():
    return await foo()

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

相关问题 更多 >

    热门问题