diff --git a/kafka/consumer.py b/kafka/consumer.py index b0d45af..9dc0db7 100644 --- a/kafka/consumer.py +++ b/kafka/consumer.py @@ -16,6 +16,6 @@ try: for message in consumer: DATETIMES.append(datetime.now()) consumer.close() -except Exception: +except KeyboardInterrupt: consumer.close() print(DATETIMES) diff --git a/kafka/publisher.py b/kafka/publisher.py index 6b9b0c1..284067d 100644 --- a/kafka/publisher.py +++ b/kafka/publisher.py @@ -11,5 +11,5 @@ try: binstring = string.encode('UTF-8') while True: producer.send('test', binstring) -except Exception: +except KeyboardInterrupt: producer.close() diff --git a/rabbit/consumer.py b/rabbit/consumer.py index ff9c6c3..e6cffef 100644 --- a/rabbit/consumer.py +++ b/rabbit/consumer.py @@ -22,6 +22,6 @@ try: channel.basic_qos(prefetch_count=1) channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True) channel.start_consuming() -except Exception: +except KeyboardInterrupt: connection.close() print(DATETIMES) diff --git a/rabbit/publisher.py b/rabbit/publisher.py index 36c5d4d..63ca1d5 100644 --- a/rabbit/publisher.py +++ b/rabbit/publisher.py @@ -10,5 +10,5 @@ try: binstring = string.encode('UTF-8') while True: channel.basic_publish(exchange="test",routing_key="test",body=binstring) -except Exception: +except KeyboardInterrupt: connection.close() diff --git a/zmq/consumer.py b/zmq/consumer.py index d5a98f0..6865f24 100644 --- a/zmq/consumer.py +++ b/zmq/consumer.py @@ -16,7 +16,6 @@ try: while True: m = socket.recv_string() DATETIMES.append(datetime.now()) -except Exception as e: - print(e) +except KeyboardInterrupt: socket.close() print(DATETIMES) \ No newline at end of file diff --git a/zmq/publisher.py b/zmq/publisher.py index 89a9262..4de94b6 100644 --- a/zmq/publisher.py +++ b/zmq/publisher.py @@ -14,5 +14,5 @@ msg_body = "a" * n try: while True: socket.send_string(f"test {msg_body}") -except Exception: +except KeyboardInterrupt: socket.close() \ No newline at end of file