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.

RedPython
  • 242
  • 1
  • 8
  • 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. – user2357112 Jun 15 '17 at 17:46
  • How long do you have between reboots? – cdarke Jun 15 '17 at 17:47
  • Connect the SD card to your PC and edit `rc.local` – DeepSpace Jun 15 '17 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. – RedPython Jun 15 '17 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. – RedPython Jun 15 '17 at 17:55
  • @DeepSpace. That sounds like an excellent idea. I will try it as soon as I can lay my hands on an SD to USB adaptor. Thanks for your assistance. – RedPython Jun 15 '17 at 17:56
  • @RedPython The way to indicate that an answer solved your problem is by accepting it (as you did), not by editing the question to say so. We also don't include thank-yous and the like in the question as they take space away from the main point and the answers. Could you revert your last edit? – David Z Jun 15 '17 at 22:14

4 Answers4

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.

FrostedCookies
  • 2,253
  • 2
  • 13
  • 15
  • 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. – RedPython Jun 15 '17 at 17:52
  • 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! – FrostedCookies Jun 15 '17 at 17:56
  • 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. – RedPython Jun 15 '17 at 18:00
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.

Ben
  • 5,952
  • 4
  • 33
  • 44
  • 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. – RedPython Jun 15 '17 at 18:07
  • 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. – RedPython Jun 15 '17 at 18:11
  • Glad to help, @RedPython! – Ben Jun 16 '17 at 02:37
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

LangeHaare
  • 2,776
  • 2
  • 17
  • 25
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"
Drahoš Maďar
  • 517
  • 2
  • 6
  • 22
  • 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? – FrostedCookies Jun 15 '17 at 17:48
  • 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. – Drahoš Maďar Jun 15 '17 at 17:53