Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python script runs on boot then reboots at end - How to regain control?

I have made a dreadful error and am looking for your help!

I have set up my raspberry pi to run a python script at start up by editing the rc.local file. This would be fine except I have written my script to reboot the raspberry pi when it exits. Now I am stuck in an infinite loop and I can't edit anything. Every time my script ends it reboots the pi and starts again!

My program uses Pygame as a GUI and I have a Raspberry Pi 3 running the NOOBS OS that came with it. If you need anymore info please ask.

Any help stopping my script so I can access the pi without losing any data will be greatly appreciated.

Edit - What an amazing community. Thank you everyone for sharing your knowledge and time. I was in a bit of a panic and you all came to my assistance really quick. If you are reading this because you are in a similar predicament I found Ben's answer was the quickest and easiest solution, but if that doesn't work for you I think FrostedCookies' idea would be the next thing to try.

like image 993
RedPython Avatar asked Jun 15 '17 17:06

RedPython


3 Answers

I'm not sure if this will work (I don't have a Pi right now), but if you can't access a terminal normally while the script is running, try the keyboard shortcut Ctrl+Alt+F1 to open one, then type sudo pkill python to kill the script (this will also kill any other python processes on your machine). Then use a terminal text editor (vi or nano perhaps) to edit your rc.local file so this doesn't happen again.

like image 123
Ben Avatar answered Nov 15 '22 18:11

Ben


Probably the easiest way is to take out the SD card from your Pi, mount the SD filesystem onto another computer running linux and edit your rc.local script from there to remove the infinite boot loop. You can also backup your data that way incase something goes wrong.

like image 36
FrostedCookies Avatar answered Nov 15 '22 19:11

FrostedCookies


It's a Raspberry Pi solution rather than a Python/unix one, but you could plug the SD card into another computer, mount it, and modify the script to stop the reboot cycle.

More information about editing the files from your Pi's SD card on another computer here: https://raspberrypi.stackexchange.com/questions/9515/how-to-access-the-rpi-root-ext4-file-system-by-inserting-sd-card-into-a-differen

like image 27
LangeHaare Avatar answered Nov 15 '22 18:11

LangeHaare