Blinkt! not clearing on exit

I’m using the example script, completely unmodified, running at boot from crontab to add some flair to my RetroPie.

When I shut down the Pi (whether through sudo shutdown, sudo reboot, a hardware power button, or the shutdown command in EmulationStation), the Blinkt lights freeze in place and remain lit.

I haven’t changed the example script at all, so it contains blinkt.set_clear_on_exit()…but the LEDs aren’t actually clearing on exit.

Is there a way to force the Blinkt lights to turn off on shutdown?

I do believe the clear on exit only works if the python script actually does an exit. The shutdown just kills it while its running and isn’t really an exit.
When I can I put my shutdown command in my python file and do my clearing just before I issue the shutdown. something like this.
os.system(“sudo shutdown now -P”)

Yeah, I see what you mean. OK, going to dive back in. Thanks!

Yeah, I have a couple of headless setups with all kinds of blinky lights on them used to display info. The main display is a Unicorn Hat HD with a scrolling text message on it. I wanted an option to shutdown but not have to unplug them. I press a button to boot them back up. I didn’t want the displays on when it was shut down though.
My shutdown command already being in my running python file made it fairly easy. Compared to any other option anyway.
The thing with these smart LED displays is they retain the last data sent to them. It just stays in the buffer as long as they have power.

Staying on is normal for both Blinkt and the other similar pHats (unicorn, scroll etc).

Some of the example Python scripts have example code that does catch keyboard interrupts (for example this one for the Scroll Phat), and that could be extended I guess to catch other interrupt cases like shutdowns.

I’m still new to this, so I really appreciate the walk-through, as well as the examples! Gonna modify my shutdown script and play around with a couple of other options as I try to figure out shutdown services…

I have the same problem. I have the Blinkt! on a loop with it changing colors randomly. After an hour or so the lights just freeze and stay the same color. I’ve modified my python program to dump to a log as its running. I can see the code continuing to change the colors but it’s not happening on the blinkt. Blinkt is keeping the same colors. I’ve added keyboard interrupt code to clear and set to black. When the lock happens even keyboard interrupt doesn’t set to black.

Also after I killed the program I run a simple script to set to black. Still doesn’t work. I have to physically pull the blinkt off the power to get it to stop.

Is it possible I have faulty hardware?

I always like to control my own exit, often via a HALT button. You can then turn everything off neatly before the program stops. Not a great deal more code but it looks neater.

Yeah, my shutdown code is called up with a button wired to a GPIO pin. Pressing the button grounds that pin.

import RPi.GPIO as GPIO
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)  

def Shutdown(channel):
        blinkt.set_all(0, 0, 0)
        os.system("sudo shutdown now -P")

GPIO.add_event_detect(5, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)