fix: error handling
This commit is contained in:
parent
6927add4b1
commit
bb41e4d8ed
@ -170,10 +170,10 @@ async def main(loop):
|
|||||||
|
|
||||||
def handler(loop, context):
|
def handler(loop, context):
|
||||||
e = context['exception']
|
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:
|
if not DEBUG:
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
|
|
||||||
loop.stop()
|
loop.stop()
|
||||||
|
|
||||||
# run
|
# run
|
||||||
@ -183,4 +183,10 @@ loop.set_exception_handler(handler)
|
|||||||
|
|
||||||
loop.create_task(main(loop))
|
loop.create_task(main(loop))
|
||||||
|
|
||||||
loop.run_forever()
|
try:
|
||||||
|
loop.run_forever()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
if not DEBUG:
|
||||||
|
GPIO.cleanup()
|
Loading…
x
Reference in New Issue
Block a user