Need to kill a python script that's autorunning on Raspberry Pi boot

Hi all, I’m hoping someone can help me fix a silly mess I’ve made!

I have built a simple Python game using the pygame library that outputs to a monitor connected to the Raspberry Pi via HDMI. The game runs in fullscreen mode.

I have triggered the game to start on boot by opening the following file:

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

and then adding this to the bottom of the file:

@/usr/bin/python /home/pi/game_filepath.py

The problem is that there is an error in the code after the game starts running in fullscreen mode. When I boot up the Pi the opening title screen appears and then the game is stuck. Because the game is running fullscreen there is no way to exit the game and get back to the desktop. If I reboot the Pi it just runs the same script with the same error and gets stuck.

There are two solutions I can think of:

  1. Force the Pi to boot to the command line. If there is a way to do this (e.g. by holding down some key combo after switching it on) then hopefully I could navigate to the autostart file and remove the line that triggers the script. Alternatively I could just remove the python script from its folder so that the autostart has nothing to trigger.

  2. SSH into the Pi - unfortunately I wasn’t able to get this to work over a remote connection before I triggered the game. I know that SSH is switched on on the Pi because I was able to SSH in when using the same wifi network. The Pi is now connected via a USB modem and I haven’t been able to connect remotely.

The Pi is a 4b (I’m not sure of the other specs as I can’t get into it any more!). Any ideas would be really appreciated.

To make matters worse - the game is actually part of a public exhibition and the organisers have had to shut it down for the day while I try to figure out how to solve the problem remotely…

EDIT: Solved now, here is the solution I ended up using in case anyone is interested.

  1. Switched Pi on and tapped ctrl+alt+F1 until it booted to the command line
  2. Navigated to a folder containing a file the script referred to early in the code.
  3. Renamed the file - this way the code errored out much earlier in the program - before it got to the full screen line.
  4. Rebooted and was taken to the desktop (because the script crashed before it got to the fullscreen line).

Once at the cli I could have navigated to the autostart file, but because I was talking a non-technical person through the process over the phone I thought this was an easier option.

If you have physical access to the pi, take out the SD card or USB drive you installed Raspberry Pi OS on, and mount the root (ext4) partition on any Linux machine or virtual machine. You’ll then have access to the file system.

1 Like

Ok that’s a good point. I don’t have access but I might be able to talk one of the onsite people through it (that said it was talking one of the onsite people through a code problem that led to this issue!).

I might have to look up how to mount the card on a virtual machine. I’m guessing I can’t just insert the card into a Mac or PC and navigate to the right file?

Thanks for your response!

1 Like

Hi Leslie,

One option that might work if you have access to another Pi locally would be to remake the project and fix the error on your local device. Then find a way to export the OS image of that Pi and send it to the remote site.
If you have a .img file you know will work your onsite person could re-flash the SD card with Raspberry Pi imager as a custom .img upload then just refit the SD card.
image

EDIT: I’ve found this which might do the trick.

That’s a good idea Trent, thanks! I don’t have another Pi with me just yet - but I could probably get one and redo it. Backing up the pi as a disk image is a clever idea. If I can’t get it solved sooner I’ll give it a go.

1 Like