Python Script in rc.local only running for ~30 seconds

What is the problem?

I know this may be more of a Raspbian question than an OctoPrint question, but I figured I would ask here first. I have created a simple shutdown button script. (Untitled - Pastebin.com). I added the script to rc.local, and it starts as expected, but the Raspberry Pi shuts down after about 30 seconds. I added a debug line to the script and it shows, but again after 30 seconds or so the Pi shuts down. Unfortunately the text on the screen just before the shutdown displays to quickly.

What did you already try to solve it?

If I remove the line from the rc.local the Pi starts and remains running. If I run the script from the command line everything works fine. The only time there is an issue is if I run the script from the rc.local. This is the line added to rc.local just before the exit 0 "python3 /home/pi/myScripts/off_button.py &"

I tried journalctl --boot, but I do not have enough time to look at the file before the shutdown. I have just enough time to edit rc.local to remove running the script before the Pi shuts down.

Have you tried running in safe mode?

No

Systeminfo Bundle

You can download this in OctoPrint's System Information dialog ... no bundle, no support!)
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
octopi_version 0.18.0
OctoPrint 1.8.7

Additional information about your setup

OctoPrint version, OctoPi version, printer, firmware, browser, operating system, ... as much data as possible

I do not have my webcam plugged in while testing, so looking at the syslog I see the webcam try to start multiple times, then I see the immediate shutdown after the multiple webcam attempts. I will plug in the webcam and test but I find it hard to believe that would be the issue.

Info from syslog that may be helpful:
2023-04-20 11:34:56,786 - octoprint.environment - INFO - Detected environment is Python 3.7.3 under Linux (linux). Details:
Apr 20 11:34:56 octopi octoprint[426]: | hardware:
Apr 20 11:34:56 octopi octoprint[426]: | cores: 4
Apr 20 11:34:56 octopi octoprint[426]: | freq: 1200.0
Apr 20 11:34:56 octopi octoprint[426]: | ram: 914006016
Apr 20 11:34:56 octopi octoprint[426]: | os:
Apr 20 11:34:56 octopi octoprint[426]: | bits: 32
Apr 20 11:34:56 octopi octoprint[426]: | id: linux
Apr 20 11:34:56 octopi octoprint[426]: | platform: linux
Apr 20 11:34:56 octopi octoprint[426]: | plugins:
Apr 20 11:34:56 octopi octoprint[426]: | pi_support:
Apr 20 11:34:56 octopi octoprint[426]: | model: Raspberry Pi 3 Model B Rev 1.2
Apr 20 11:34:56 octopi octoprint[426]: | octopi_version: 0.18.0
Apr 20 11:34:56 octopi octoprint[426]: | octopiuptodate_build: 0.18.0-1.8.6-20221018093204
Apr 20 11:34:56 octopi octoprint[426]: | throttle_check_enabled: true
Apr 20 11:34:56 octopi octoprint[426]: | throttle_check_functional: true
Apr 20 11:34:56 octopi octoprint[426]: | throttle_state: '0x0'
Apr 20 11:34:56 octopi octoprint[426]: | python:
Apr 20 11:34:56 octopi octoprint[426]: | pip: 20.3.3
Apr 20 11:34:56 octopi octoprint[426]: | version: 3.7.3
Apr 20 11:34:56 octopi octoprint[426]: | virtualenv: /home/pi/oprint#033[0m

I removed the shutdown -h now and replaced it with a print command and found that the button was being triggered (switching to low). I will try another script, one that uses GPIO.wait_for_edge falling or add some debounce to prevent false button presses.

I have tried a new script with 100% does not fail when launched from the command line, but if added to rc.local after about 30 seconds the callback in the script runs. This new script requires the button to be pressed for 2 seconds so it is not bounce or floating values.

NEW Script. Untitled - Pastebin.com

Try nohup at the beginning of the line you added

With nohup the system still shuts down running my shutdown script. With different scripts it appears, after 30 seconds the GPIO switches state triggering which ever event I have comfigured then the program exits.

I tried a totally different type of script, one that uses GPIOZero with button and OutputDevice to control a relay with a button. From the command line the script works fine. Adding it to rc.local, the script runs for about 30 seconds at startup then stops. I guess I need to look into another way of running scripts at startup.

Solved: Changes GPIO pins and it is fixed. Do not know what was causing the GPIO to work for 30 seconds then stop, but at least I can move forward now. I may look into it in the future.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.