magdalinka
Posts: 1
Joined: Tue Jun 26, 2018 8:11 am

Running a never ending loop Python script at startup

Tue Jun 26, 2018 8:25 am

Hi,

I have a problem with running the python code! It runs on startup, and then stops. The python code contains "while loop" so It should never stop. When I write it in console manualy then it is working in the background but if I write it in rc.local It works only on the start up.
Here is my rc.local code: "sudo python /home/pi/my_directory/code_name.py & "

How to make it run in background automaticly?

DirkS
Posts: 9876
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Running a never ending loop Python script at startup

Tue Jun 26, 2018 8:54 am

magdalinka wrote:
Tue Jun 26, 2018 8:25 am
Hi,

I have a problem with running the python code! It runs on startup, and then stops. The python code contains "while loop" so It should never stop. When I write it in console manualy then it is working in the background but if I write it in rc.local It works only on the start up.
Here is my rc.local code: "sudo python /home/pi/my_directory/code_name.py & "

How to make it run in background automaticly?
You will have a much better chance of a helpful response if you start a new topic instead of reviving a 5 year old one...

Heater
Posts: 12974
Joined: Tue Jul 17, 2012 3:02 pm

Re: Running a never ending loop Python script at startup

Tue Jun 26, 2018 8:56 am

magdalinka,
How to make it run in background automaticly?
A nice easy way to do this is to use the systemd. systemd is the initialization system of Raspbian.

See my post here: viewtopic.php?t=138861#p921354

See this little thread where someone gets Python running at startup using systemd: viewtopic.php?t=216371

You will find examples, blogs and tutorials about using systemd all over the net.

texy
Forum Moderator
Forum Moderator
Posts: 5155
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Running a never ending loop Python script at startup

Tue Jun 26, 2018 10:13 am

DirkS wrote:
Tue Jun 26, 2018 8:54 am
magdalinka wrote:
Tue Jun 26, 2018 8:25 am
Hi,

I have a problem with running the python code! It runs on startup, and then stops. The python code contains "while loop" so It should never stop. When I write it in console manualy then it is working in the background but if I write it in rc.local It works only on the start up.
Here is my rc.local code: "sudo python /home/pi/my_directory/code_name.py & "

How to make it run in background automaticly?
You will have a much better chance of a helpful response if you start a new topic instead of reviving a 5 year old one...
Split from original instead.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Return to “Python”