From f1505037b1f4a1ef4d69dbac99b126e33e295950 Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Thu, 12 May 2022 23:25:14 -0400 Subject: [PATCH] move the event loop to a main() function --- buttond.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/buttond.py b/buttond.py index fdee35a..8628a87 100755 --- a/buttond.py +++ b/buttond.py @@ -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()')