It's common to see the use of signal.pause() or an equivalent construct in GPIO examples and programs:Â
signal.pause() # Stops program from exiting. # (8)
Line (8) prevents the main program thread from reaching its natural end, which under normal circumstances is where the program terminates.
Forgetting to add signal.pause() to the end of a GPIO-interfacing Python program is a common and often confusing mistake when starting out. If your program exits immediately after it's started, try adding signal.pause() at the end of your program as a first step.
We didn't need signal.pause()Â with our previous LED flashing examples. Here is why:
- Our GPIOZero example (chapter02/led_gpiozero.py) used background=False in the LED constructor. This prevented our program from exiting by keeping the LED's thread in the foreground.
- In the PiGPIO example (chapter02/led_pigpio.py), it's the while loop that...