fix: error handling

This commit is contained in:
Tony Yang 2023-05-03 15:34:56 +08:00
parent 6927add4b1
commit bb41e4d8ed
Signed by: t510599
GPG Key ID: D88388851C28715D

View File

@ -170,10 +170,10 @@ async def main(loop):
def handler(loop, context):
e = context['exception']
print(*traceback.format_exception(None, e, e.__traceback__), file=sys.stderr, flush=True)
if not isinstance(e, KeyboardInterrupt):
print(*traceback.format_exception(None, e, e.__traceback__), file=sys.stderr, flush=True)
if not DEBUG:
GPIO.cleanup()
loop.stop()
# run
@ -183,4 +183,10 @@ loop.set_exception_handler(handler)
loop.create_task(main(loop))
loop.run_forever()
try:
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
if not DEBUG:
GPIO.cleanup()