From b8a4875e9d154a0359f04455190d0b1aaa5099b0 Mon Sep 17 00:00:00 2001 From: cheezedoodle2 Date: Thu, 18 May 2023 14:45:18 -0700 Subject: [PATCH] Wrapped the publish call to catch DeadlineExceeded exceptions --- fp2_10.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fp2_10.py b/fp2_10.py index baf21ef..d459cf2 100644 --- a/fp2_10.py +++ b/fp2_10.py @@ -41,7 +41,7 @@ subscription = subscriber.create_subscription( # Publish a message to the topic # Read the data from the csv file # file_path = "C:/Users/Karen/Desktop/zipcodes.csv" -file_path = "C:/Users/Karen/Desktop/zipcodes.csv" +file_path = "zipcodes.csv" with open(file_path, "r") as csv_file: reader = csv.reader(csv_file) @@ -49,7 +49,10 @@ with open(file_path, "r") as csv_file: for row in reader: # Format the data as a string and publish it to the topic data = ",".join(row).encode("utf-8") - future = publisher.publish(topic_path, data) + try: + future = publisher.publish(topic_path, data) + except DeadlineExceeded as de: + print(f"Caught DeadlineExceeded exception: {de}") print(f"Published message ID {future.result()}") '''