How to Prevent Damage to Raspberry Pi GPIO Pins (Linux Signal Handling with Python)

Опубликовано: 06 Май 2026
на канале: M Heidenreich
9,300
163

Program termination with GPIO pins active on the Raspberry Pi requires special attention, otherwise the GPIO ports may not close correctly. This video provides practical information how to structure Python programs so they automatically restore GPIO state to default (safe) state when they exit. Normal program execution as well as handling of common Linux termination signals is covered.

While this concept is explained with Raspberry Pi the same procedures can be also considered in general for Python programming on Linux. Other signals (not-terminating) can be handled using similar approach. Very similar syntax is used in C programs.

0:00 Intro
1:20 Keyboard Interrupt (SIGINT Signal)
3:14 Soft Kill Command (SIGTERM Signal)
6:50 Hard Kill Command (SIGKILL Signal)
7:30 Terminal Closing (SIGHUP Signal)
10:17 The "finally" Block

Disclaimer:
"Raspberry Pi" and the distinct logo are a trademark of the Raspberry Pi Foundation.