Skip to content

Commit

Permalink
Added timeout in error handling [(#1636)](GoogleCloudPlatform/python…
Browse files Browse the repository at this point in the history
  • Loading branch information
anguillanneuf authored and plamut committed Jul 10, 2020
1 parent 77043fb commit 5d56a16
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion samples/snippets/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions samples/snippets/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down

0 comments on commit 5d56a16

Please sign in to comment.