Skip to content

Commit 86a0758

Browse files
committed
Updated comments
1 parent fbfb19d commit 86a0758

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pubsub/cloud-client/quickstart.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def end_to_end(project_id, topic_name, subscription_name, num_messages):
4343
subscription_path = subscriber.subscription_path(
4444
project_id, subscription_name)
4545

46-
# Create the topic.
46+
# Create a topic.
4747
try:
4848
publisher.delete_topic(topic_path)
4949
except NotFound:
@@ -87,7 +87,7 @@ def end_to_end(project_id, topic_name, subscription_name, num_messages):
8787
def callback(message):
8888
# Unacknowledged messages will be sent again.
8989
message.ack()
90-
# Populate message `subtime`.
90+
# Update message `subtime`.
9191
tracker[message.message_id]['subtime'] = time.time()
9292

9393
# Receive messages. The subscriber is nonblocking.
@@ -96,14 +96,17 @@ def callback(message):
9696
print('\nListening for messages...')
9797

9898
while True:
99+
# Deplete messages in `tracker` every time we have complete info
100+
# of a message.
99101
for msg_id in list(tracker):
100102
pubtime = tracker[msg_id]['pubtime']
101103
subtime = tracker[msg_id]['subtime']
102104
if subtime is not None:
103105
pubsub_time += subtime - pubtime
104106
del tracker[msg_id]
105107

106-
# Exit if all the messages have been acknowledged.
108+
# Exit if `tracker` is empty i.e. all the messages' publish-subscribe
109+
# time have been accounted for.
107110
if len(tracker) == 0:
108111
print('\nTotal publish to subscribe time for {} messages: \
109112
{:.6f}s.'.format(num_messages, pubsub_time))

0 commit comments

Comments
 (0)