Skip to content

Commit 810226f

Browse files
committed
Better handling of KeyboardInterrupt and Exceptions during loop.
1 parent a89da34 commit 810226f

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

arduino/arduino.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,16 @@ def start(setup=None, loop=None, cleanup = None, preload = None):
139139
setup()
140140
try:
141141
while True:
142-
try:
143-
if loop is not None:
144-
loop()
145-
if not NON_BLOCKING:
146-
sleep_ms(1)
147-
148-
except (Exception, KeyboardInterrupt) as e:
149-
if cleanup is not None:
150-
cleanup()
151-
if not isinstance(e, KeyboardInterrupt):
152-
raise e
153-
else:
154-
break
142+
if loop is not None:
143+
loop()
144+
if not NON_BLOCKING:
145+
sleep_ms(1)
155146
except (Exception, KeyboardInterrupt) as e:
156-
if cleanup is not None:
157-
cleanup()
158-
if not isinstance(e, KeyboardInterrupt):
159-
raise e
147+
if cleanup is not None:
148+
cleanup()
149+
if not isinstance(e, KeyboardInterrupt):
150+
raise e
151+
160152

161153
if __name__ == '__main__':
162154
start(setup, loop, cleanup)

0 commit comments

Comments
 (0)