Persistent Python script running in background?

The Raspberry Pi is a series of credit card-sized single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools and developing countries.

Post Reply
User avatar
/RaspberryPi
Corporate
Posts: 2449
Joined: Wed Jun 05, 2019 1:29 am

Persistent Python script running in background?

Post by /RaspberryPi »

Here is the scenario:
Raspberry Pi with two reed switches wired to the GPIO. I am using GPIO.add_event_detect() to perform actions on the switches when they either open or close. I need this script to run at boot and stay running in the background.
I am having a hard time finding the right way to keep the script persistent. The original sample code I found (when learning about the event detection) had me do:
message = input("") Just to keep the script "active". Is this the right/proper way to do this? I know it won't work with nohup since it is asking for user input. Unfortunately the script needs to run 24/7 and can't be scheduled via cronjob. Haven't tried "daemonizing" it, and wanted to get some input here first.
Thanks!

submitted by /u/SneakyPackets
[link] [comments]

More...
Post Reply

Return to “Raspberry Pi Forum”