From 53b0f85ebb796e4b9d9191dcd838e3b437108a08 Mon Sep 17 00:00:00 2001 From: gryf Date: Sun, 28 Feb 2021 10:12:16 +0100 Subject: [PATCH] Handle keyboard interrupt exception for status with loop. --- linak_ctrl.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/linak_ctrl.py b/linak_ctrl.py index d2caed1..71fb0f2 100755 --- a/linak_ctrl.py +++ b/linak_ctrl.py @@ -115,12 +115,15 @@ class LinakDevice: def get_position(self, loop=False): if loop: - while True: - report = self._get_report() - LOG.warning('Position: %s, height: %.2fcm, moving: %s', - report.position, report.position_in_cm, - report.moving) - time.sleep(0.2) + try: + while True: + report = self._get_report() + LOG.warning('Position: %s, height: %.2fcm, moving: %s', + report.position, report.position_in_cm, + report.moving) + time.sleep(0.2) + except KeyboardInterrupt: + return else: report = self._get_report() LOG.warning('Position: %s, height: %scm, moving: %s',