diff --git a/samples/snippets/publisher.py b/samples/snippets/publisher.py index 96caba9f4..a577abc63 100644 --- a/samples/snippets/publisher.py +++ b/samples/snippets/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(): + # When timeout is unspecified, the exception method waits indefinitely. + if message_future.exception(timeout=30): print('Publishing message on {} threw an Exception {}.'.format( topic_name, message_future.exception())) else: diff --git a/samples/snippets/subscriber.py b/samples/snippets/subscriber.py index 46bb51188..51fa96b86 100644 --- a/samples/snippets/subscriber.py +++ b/samples/snippets/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() + # When timeout is unspecified, the result method waits indefinitely. + subscription.future.result(timeout=30) except Exception as e: print( 'Listening for messages on {} threw an Exception: {}.'.format( subscription_name, e)) - raise # [END pubsub_subscriber_error_listener]