def main(): try: counter = count(1) with MotionSensor(11) as pir: pir.when_motion = lambda: counting(counter) signal.pause() except KeyboardInterrupt: pass