1
0
Fork 0

move the event loop to a main() function

This commit is contained in:
Kevin Matz 2022-05-12 23:25:14 -04:00
parent 35d20682fc
commit f1505037b1
1 changed files with 11 additions and 4 deletions

View File

@ -28,6 +28,16 @@ from gpiozero import Button, GPIODeviceError
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
def main():
"""Entry point for direct execution."""
## run the event loop
try:
pause()
except KeyboardInterrupt:
print()
def activate(macro):
"""Sanitize user configured macros."""
if macro is None:
@ -79,10 +89,7 @@ except NameError as e:
# when run directly, sleep until button signal or KeyboardInterrupt
if __name__ == '__main__':
try:
pause()
except KeyboardInterrupt:
print()
main()
else:
# indicate prefered method of sleeping when laoded as a module
log.debug('call signal.pause() instead of time.sleep()')