python - 可以或如何在 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())
推荐阅读
- microsoft-teams - Teams Toolkit - 无法预配“应用服务计划”
- angular - 错误无法读取未定义的属性导航?
- flask - 如果我把 __name__=="__main__" 放在 Flask 中,则为 404
- azure - 如何在 Azure 中引入文件?
- python - 删除python列表中的重复项
- node.js - Mongo 连接到 localhost 虽然 conn 字符串在应用程序中是正确的
- css - 我怎样才能把下拉列表放在其他组件的前面,我已经尝试了所有我知道的东西,但是我没有解决这个错误请帮忙
- php - Symfony5 SQS 消费者无效的访问密钥
- reactjs - Github Actions 在 JS monorepo 本地导入上构建失败
- php - 使用数据透视表按类别 ID 获取产品