Skip to content

Commit 3af21e5

Browse files
committed
Add double checked catch clause
1 parent 5029940 commit 3af21e5

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

arduino/arduino.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -137,43 +137,31 @@ def cleanup():
137137
print()
138138
print()
139139

140-
141-
def frame_counter():
142-
global frame_count
143-
frame_count += 1
144-
try:
145-
sleep_ms(1)
146-
return True
147-
except (Exception, KeyboardInterrupt) as e:
148-
if cleanup is not None:
149-
cleanup()
150-
if not isinstance(e, KeyboardInterrupt):
151-
raise e
152-
return False
153-
154140

155141
# RUNTIME
156142
def start(setup=None, loop=None, cleanup = None, preload = None):
157143
if preload is not None:
158144
preload()
159145
if setup is not None:
160146
setup()
161-
while True:
162-
try:
163-
if loop is not None:
164-
loop()
165-
if not frame_counter():
147+
try:
148+
while True:
149+
try:
150+
if loop is not None:
151+
loop()
152+
153+
except (Exception, KeyboardInterrupt) as e:
166154
if cleanup is not None:
167155
cleanup()
156+
if not isinstance(e, KeyboardInterrupt):
157+
raise e
158+
else:
168159
break
169-
170-
except (Exception, KeyboardInterrupt) as e:
171-
if cleanup is not None:
172-
cleanup()
173-
if not isinstance(e, KeyboardInterrupt):
174-
raise e
175-
else:
176-
break
160+
except (Exception, KeyboardInterrupt) as e:
161+
if cleanup is not None:
162+
cleanup()
163+
if not isinstance(e, KeyboardInterrupt):
164+
raise e
177165

178166
if __name__ == '__main__':
179167
start(setup = setup, loop = loop, cleanup = cleanup, preload = preload)

0 commit comments

Comments
 (0)