Run python script on startup on Raspberry Pi [help]

Larry_The_Great

Honorable
Jan 16, 2014
41
0
10,530
Hi, I'm wondering if anyone could help me with this simple task. I have a python script that I want to run in the terminal GUI on the desktop every time the pi starts up. I am using a RP3 and running the latest version of raspbian. The intent is for the script to run until I manually stop it as it uses a for loop that doesn't end (I understand this probably terrible coding but I have it for a reason). One solution I tried seemed to work however, it launched in the background before I got to the desktop and obviously because of the endless loop this wasn't what I wanted as I never got to the desktop. I have tried everything I could find on google and I am stumped. I tried using cron, I've edited rc.local and init.d, trying to launch a shell script plus many others and all to no prevail. This is probably something simple but I would really appreciate any help! Thanks in advance.
 
Solution
Running an infinite loop is indeed a bad idea when there are tools that already exist for you to use. You should probably look into making a simple systemd service unit file.

Or you can place your script in the .xinitrc file if you are feeling adventurous.

Plenty of examples and various debian/arch wiki on how to do this.
Running an infinite loop is indeed a bad idea when there are tools that already exist for you to use. You should probably look into making a simple systemd service unit file.

Or you can place your script in the .xinitrc file if you are feeling adventurous.

Plenty of examples and various debian/arch wiki on how to do this.
 
Solution