10

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.

7
  • Speaking as someone who's never used a Raspberry Pi, it sounds like you could stop it by disconnecting the power. Whether that would preserve the data you want to access, I don't know. Commented Jun 15, 2017 at 17:46
  • How long do you have between reboots? Commented Jun 15, 2017 at 17:47
  • Connect the SD card to your PC and edit rc.local Commented Jun 15, 2017 at 17:47
  • Thanks user2357112. Your help is much appreciated. Disconnecting the power does stop it, but it starts as soon as I plug it in again. Commented Jun 15, 2017 at 17:48
  • @cdarke I actually get to see the prompt for about 2 seconds before the pygame window opens (in fullscreen mode) but it isn't long enough to type more than about 6 characters. Commented Jun 15, 2017 at 17:55

4 Answers 4

8

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks FrostedCookies. That sound like it will solve the problem. Hopefully I can edit the rc.local file on a windows PC. Unfortunately I haven't got a SD card to USB adaptor available at the moment, so that might be my cue to go home from work, get some rest and try again tomorrow.
Hey Red, I think the NOOBs filesystem uses a linux filesystem format (ext4) so windows won't likely be able to mount it. There are a few options, you can either boot a temporary linux distro on your PC using a bootable flash or live distribution, or you can install a linux virtual machine on windows to mount it. Keep us posted!
Thanks Frosted. I am not sure I understand anything after the word NOOBs, but I genuinely appreciate your time helping out and will definitely keep you informed.
5

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.

3 Comments

Thanks for your valuable input Ben, I think we are getting somewhere with this idea. Pressing Ctrl+Alt+F1 showed me the terminal just like you said it would, and typing sudo pkill python stopped Pygame running in the background. The only problem now is after typing that instruction the keyboard become unresponsive.
Hey Ben, You did it! Thank you so much, I had to adjust your idea a bit, Instead of typing 'sudo pkill python' I just typed 'sudo nano /etc/rc.local' and edited the file. All fixed. Thanks again for your help.
Glad to help, @RedPython!
2

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

Comments

0

I'd firstly turn it off and on again..

If it wont help

  • ps aux | grep -i python
  • killall python - youll probably need to tweak the killall command with the python script name instead or in addition to "python"

2 Comments

the only issue I can imagine with this is that he's stuck in an infinite boot loop so how will he have time to get a console open and enter the kill command before his rc.local is run and reboots?
Well depends whats the script doing, but it could complicate things a bit :-) Anyway, turning it off and accessing the code from another device would help if this is not possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.