From bcc6213aad16ebf8512663124b45b00d8bc8f7eb Mon Sep 17 00:00:00 2001 From: Tianzi Cai Date: Wed, 15 Aug 2018 14:33:21 -0700 Subject: [PATCH 1/5] Added timeout for error handling --- pubsub/cloud-client/publisher.py | 3 ++- pubsub/cloud-client/subscriber.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pubsub/cloud-client/publisher.py b/pubsub/cloud-client/publisher.py index 96caba9f4735..f5907ea97e46 100644 --- a/pubsub/cloud-client/publisher.py +++ b/pubsub/cloud-client/publisher.py @@ -131,7 +131,8 @@ def publish_messages_with_error_handler(project, topic_name): topic_path = publisher.topic_path(project, topic_name) def callback(message_future): - if message_future.exception(): + # Attempts to publish for 10 seconds, then times out. + if message_future.exception(timeout = 10): print('Publishing message on {} threw an Exception {}.'.format( topic_name, message_future.exception())) else: diff --git a/pubsub/cloud-client/subscriber.py b/pubsub/cloud-client/subscriber.py index 46bb5118843b..8d12abd92251 100644 --- a/pubsub/cloud-client/subscriber.py +++ b/pubsub/cloud-client/subscriber.py @@ -223,12 +223,12 @@ def callback(message): # Blocks the thread while messages are coming in through the stream. Any # exceptions that crop up on the thread will be set on the future. try: - subscription.future.result() + # Attempts to subscribe for 10 seconds, then times out. + subscription.future.result(timeout = 10) except Exception as e: print( 'Listening for messages on {} threw an Exception: {}.'.format( subscription_name, e)) - raise # [END pubsub_subscriber_error_listener] From a77c40d21bc0000b859ca4569709170b64ac56b1 Mon Sep 17 00:00:00 2001 From: Tianzi Cai Date: Wed, 15 Aug 2018 14:37:12 -0700 Subject: [PATCH 2/5] Added timeout for error handling --- pubsub/cloud-client/publisher.py | 2 +- pubsub/cloud-client/subscriber.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pubsub/cloud-client/publisher.py b/pubsub/cloud-client/publisher.py index f5907ea97e46..fd328d3f9736 100644 --- a/pubsub/cloud-client/publisher.py +++ b/pubsub/cloud-client/publisher.py @@ -131,7 +131,7 @@ def publish_messages_with_error_handler(project, topic_name): topic_path = publisher.topic_path(project, topic_name) def callback(message_future): - # Attempts to publish for 10 seconds, then times out. + # Attempts to publish for 10 seconds, then times out. Defaults to None. if message_future.exception(timeout = 10): print('Publishing message on {} threw an Exception {}.'.format( topic_name, message_future.exception())) diff --git a/pubsub/cloud-client/subscriber.py b/pubsub/cloud-client/subscriber.py index 8d12abd92251..c9fb68495f60 100644 --- a/pubsub/cloud-client/subscriber.py +++ b/pubsub/cloud-client/subscriber.py @@ -223,7 +223,7 @@ def callback(message): # Blocks the thread while messages are coming in through the stream. Any # exceptions that crop up on the thread will be set on the future. try: - # Attempts to subscribe for 10 seconds, then times out. + # Attempts to subscribe for 10 seconds then times out. Defaults to None. subscription.future.result(timeout = 10) except Exception as e: print( From 6ecd4c85afcff5a9e288e6fd5cae08bf5c42fff6 Mon Sep 17 00:00:00 2001 From: Tianzi Cai Date: Wed, 15 Aug 2018 14:49:04 -0700 Subject: [PATCH 3/5] Reformatted comments --- pubsub/cloud-client/publisher.py | 5 +++-- pubsub/cloud-client/subscriber.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pubsub/cloud-client/publisher.py b/pubsub/cloud-client/publisher.py index fd328d3f9736..8c7a34817cbb 100644 --- a/pubsub/cloud-client/publisher.py +++ b/pubsub/cloud-client/publisher.py @@ -131,8 +131,9 @@ def publish_messages_with_error_handler(project, topic_name): topic_path = publisher.topic_path(project, topic_name) def callback(message_future): - # Attempts to publish for 10 seconds, then times out. Defaults to None. - if message_future.exception(timeout = 10): + # Attempts to publish for 10 seconds, then times out. + # Defaults to None. + if message_future.exception(timeout=10): print('Publishing message on {} threw an Exception {}.'.format( topic_name, message_future.exception())) else: diff --git a/pubsub/cloud-client/subscriber.py b/pubsub/cloud-client/subscriber.py index c9fb68495f60..f5d6bc7cc654 100644 --- a/pubsub/cloud-client/subscriber.py +++ b/pubsub/cloud-client/subscriber.py @@ -223,8 +223,9 @@ def callback(message): # Blocks the thread while messages are coming in through the stream. Any # exceptions that crop up on the thread will be set on the future. try: - # Attempts to subscribe for 10 seconds then times out. Defaults to None. - subscription.future.result(timeout = 10) + # Attempts to subscribe for 10 seconds, then times out. + # Defaults to None. + subscription.future.result(timeout=10) except Exception as e: print( 'Listening for messages on {} threw an Exception: {}.'.format( From 456a434702f08f88ec42eb6aa0cb269241f417c8 Mon Sep 17 00:00:00 2001 From: Tianzi Cai Date: Wed, 15 Aug 2018 15:21:00 -0700 Subject: [PATCH 4/5] Rewrote comments --- pubsub/cloud-client/publisher.py | 3 +-- pubsub/cloud-client/subscriber.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pubsub/cloud-client/publisher.py b/pubsub/cloud-client/publisher.py index 8c7a34817cbb..2bc482bf8650 100644 --- a/pubsub/cloud-client/publisher.py +++ b/pubsub/cloud-client/publisher.py @@ -131,8 +131,7 @@ def publish_messages_with_error_handler(project, topic_name): topic_path = publisher.topic_path(project, topic_name) def callback(message_future): - # Attempts to publish for 10 seconds, then times out. - # Defaults to None. + # When timeout is unspecified, the exception method waits indefinitely. if message_future.exception(timeout=10): print('Publishing message on {} threw an Exception {}.'.format( topic_name, message_future.exception())) diff --git a/pubsub/cloud-client/subscriber.py b/pubsub/cloud-client/subscriber.py index f5d6bc7cc654..747c706c4d62 100644 --- a/pubsub/cloud-client/subscriber.py +++ b/pubsub/cloud-client/subscriber.py @@ -223,8 +223,7 @@ def callback(message): # Blocks the thread while messages are coming in through the stream. Any # exceptions that crop up on the thread will be set on the future. try: - # Attempts to subscribe for 10 seconds, then times out. - # Defaults to None. + # When timeout is unspecified, the result method waits indefinitely. subscription.future.result(timeout=10) except Exception as e: print( From 80d297349c19f634320dc2ce08dc54c3ffab8d74 Mon Sep 17 00:00:00 2001 From: Tianzi Cai Date: Wed, 15 Aug 2018 15:53:23 -0700 Subject: [PATCH 5/5] Increated timeout to pass tests --- pubsub/cloud-client/publisher.py | 2 +- pubsub/cloud-client/subscriber.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pubsub/cloud-client/publisher.py b/pubsub/cloud-client/publisher.py index 2bc482bf8650..a577abc63721 100644 --- a/pubsub/cloud-client/publisher.py +++ b/pubsub/cloud-client/publisher.py @@ -132,7 +132,7 @@ def publish_messages_with_error_handler(project, topic_name): def callback(message_future): # When timeout is unspecified, the exception method waits indefinitely. - if message_future.exception(timeout=10): + if message_future.exception(timeout=30): print('Publishing message on {} threw an Exception {}.'.format( topic_name, message_future.exception())) else: diff --git a/pubsub/cloud-client/subscriber.py b/pubsub/cloud-client/subscriber.py index 747c706c4d62..51fa96b86759 100644 --- a/pubsub/cloud-client/subscriber.py +++ b/pubsub/cloud-client/subscriber.py @@ -224,7 +224,7 @@ def callback(message): # exceptions that crop up on the thread will be set on the future. try: # When timeout is unspecified, the result method waits indefinitely. - subscription.future.result(timeout=10) + subscription.future.result(timeout=30) except Exception as e: print( 'Listening for messages on {} threw an Exception: {}.'.format(