From 9cbacf3751e31a42f40b4aef89d89ed0d1bf5a4f Mon Sep 17 00:00:00 2001
From: Thomas Kluyver <thomas@kluyver.me.uk>
Date: Thu, 18 Mar 2021 17:11:07 +0000
Subject: [PATCH] Hide traceback after Ctrl-C

---
 webservice/listen_kafka.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/webservice/listen_kafka.py b/webservice/listen_kafka.py
index 2c5e155ab..b0dcbb42a 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()
-- 
GitLab