简体   繁体   English

Python Google Cloud PubSub超时异常

[英]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.

相关问题 无法在Python中正确调用Google Cloud PubSub - Google Cloud PubSub not being called properly in Python Python external_dependencies:“ google-cloud-pubsub”无效 - Python external_dependencies: 'google-cloud-pubsub' not working 在谷歌云中使用 PubSub function - Consume PubSub in Google cloud function 带有python的Google Pubsub模拟器 - Google Pubsub emulator with python Python中的Google Cloud Datastore超时错误 - Google Cloud Datastore timeout errors in python 未通过回调处理的Google Cloud PubSub消息 - Google Cloud PubSub messages not processed by callback 获取 Google Cloud PubSub 中单条消息的大小 - Get the size of a single message in Google Cloud PubSub Google Cloud Dataflow - 从 PubSub 到 Parquet - Google Cloud Dataflow - From PubSub to Parquet Google Cloud Dataflow-Python将JSON流传输到PubSub-DirectRunner和DataflowRunner之间的区别 - Google Cloud Dataflow - Python Streaming JSON to PubSub - Differences between DirectRunner and DataflowRunner Cloud Run (Python) 中 GCS Bucket 上传调用的 Google PubSub Push SubscriptionTimeouts - Google PubSub Push SubscriptionTimeouts from GCS Bucket upload call in Cloud Run (Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM