python - 如何使用 Google Cloud get_operation?

标签 python google-cloud-platform google-cloud-functions grpc google-speech-api

我正在尝试使用 OperationsClient get_operation() 函数,以便我可以轮询长时间运行的任务并获取其状态。

https://google-cloud-python.readthedocs.io/en/stable/core/operations_client.html#google.api_core.operations_v1.OperationsClient.get_operation

代码看起来相当简单:

api = operations_v1.OperationsClient()
response = api.get_operation(name)

但是,OperationClient 的初始化需要一个 channel :OperationsClient(channel)。我不知道什么是channel是做什么的或者它是如何创建的。

任何帮助表示赞赏。谢谢

最佳答案

来自您链接的文档:

channel (grpc.Channel) – The gRPC channel associated with the service that implements the google.longrunning.operations interface.

因此,如果它是您自己的 gRPC 服务,您将需要执行以下操作:

import grpc
channel = grpc.insecure_channel('localhost:50051')
api = operations_v1.OperationsClient(channel)
response = api.get_operation(name)

根据您尝试轮询的长期运行服务,您可能需要改用其 channel 。

关于python - 如何使用 Google Cloud get_operation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55056835/

相关文章:

python - 按降序对列表 : numbers in ascending, 字母进行排序

python - Pandas 数据框中的新列基于现有列中变量的值

google-cloud-platform - 是否可以通过 ssh 使用 Google Cloud Shell?

google-maps - 在 Google Cloud 项目上启用结算功能

google-cloud-platform - 如何使用 cli 或控制台列出 GCP 中的组 ID

python - django 应用程序的正确模型结构?

python - 在python中删除文本文件的第一行

javascript - 运行 Firebase 函数测试时出现 "path"中的类型错误

aws-lambda - 将路径参数传递给 Google 的 Cloud Function 端点

google-cloud-functions - 谷歌物联网核心: how do I know which device the message is coming from?