diff --git a/webservice/listen_kafka.py b/webservice/listen_kafka.py
index 2c5e155abbaaec41a663a24154ac911e25bba1e1..b0dcbb42a72841d96f6e6135bdaca11f45a8a929 100644
--- a/webservice/listen_kafka.py
+++ b/webservice/listen_kafka.py
@@ -19,6 +19,10 @@ print(f"brokers: {brokers!r}")
 kc = KafkaConsumer(topic, bootstrap_servers=brokers)
 
 print("Waiting for messages (Ctrl-C to quit)...")
-for record in kc:
-    msg = json.loads(record.value.decode())
-    print(msg)
+try:
+    for record in kc:
+        msg = json.loads(record.value.decode())
+        print(msg)
+except KeyboardInterrupt:
+    print("Exiting")
+    kc.close()