[英]Python Google Cloud PubSub TimeOut Exception
I am busy working with PubSub using Google Cloud and I have implemented Google PubSub Subscribers and the stack is working as expected however I sometimes get an issue whereby a timeout occurs on my callback and then the subscriber thread seems to hang as seen below: 我正在使用Google Cloud处理PubSub,并且已经实现了Google PubSub Subscriber,并且堆栈按预期工作,但是有时我遇到一个问题,即回调发生超时,然后订阅线程似乎挂起,如下所示:
DEBUG 2019-08-14 09:49:13,130 google.cloud.pubsub_v1.subscriber.policy.thread.dispatch_callback:287- Handling 1 batched requests
DEBUG 2019-08-14 09:49:15,441 google.cloud.pubsub_v1.subscriber.policy.base.maintain_leases:347- The current p99 value is 10 seconds.
DEBUG 2019-08-14 09:49:15,442 google.cloud.pubsub_v1.subscriber.policy.base.maintain_leases:397- Snoozing lease management for 2.925854 seconds.
ERROR 2019-08-14 09:49:16,315 models.subscribe:104- Subscriber Timeout occurred Timed out waiting for result.
This is specifically the error: 这是具体的错误:
Timed out waiting for result.
Which is described in the google cloud docs here . 这在google cloud文档中进行了介绍 。
My actual subscriber code and exception handling is as follows: 我的实际订户代码和异常处理如下:
protocol = self.get_subscriber_protocol()
logger.info("Starting subscriber %s on topic %s", os.environ.get('PUBSUB_CLIENT_ID'), topic)
future = protocol.subscribe(topic,
callback=callback,
always_raise=False,
create_topic=True,
exception_handler=exception_handler)
try:
future.result(timeout=120)
except TimeoutError as te:
logger.error("Subscriber Timeout occurred {}".format(te))
except Exception as e:
logger.error(e)
From what I understand, if a Time out occurs then the subscriber should log a message and discard that message however instead it seems to block the thread. 据我了解,如果发生超时,则订户应记录一条消息并丢弃该消息,但是似乎阻塞了线程。
I was just wondering if anyone has experienced this and what would be the best approach to handle this case? 我只是想知道是否有人经历过这种情况,而处理这种情况的最佳方法是什么?
Thanks! 谢谢!
When you call protocol.subscribe()
, are you retrieving the future returned by subscribe()
in the Pub/Sub Python client library? 当您调用
protocol.subscribe()
,您是否正在检索Pub / Sub Python客户端库中的subscribe()
返回的未来? If so, you should not call result()
with a timeout on that future. 如果是这样,则不应在该将来发生超时的情况下调用
result()
。 https://googleapis.github.io/google-cloud-python/latest/pubsub/subscriber/api/client.html#google.cloud.pubsub_v1.subscriber.client.Client.subscribe https://googleapis.github.io/google-cloud-python/latest/pubsub/subscriber/api/client.html#google.cloud.pubsub_v1.subscriber.client.Client.subscribe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.