- Does you code need to be run as root? If not don't do so.
- Depending on which OS and which release of it, your Pi may not be using Pulse Audio. RPiOS Bookworm, for example, defaults to using Pipewire.
- Handle the error in your code rather than letting it barf. In pseudo code:Or in pseudo python:
Code:
while true: if sound is not available: sleep for a bit else: breakCode:
import timewhile true: try: # do something that will trigger the exception here break except Exception: time.sleep(5) - redvli has given you the best solution if you don't want to do that.
- For a hacky solution, set your Pi to boot to command line with automatic login and run your code from your $HOME/.bashrc. The downside is you will need to take steps to stop your process running more than once as your .bashrc gets run at every login.
For exampe:Code:
if [ `tty` = "/dev/tty1'"; then # only run if logged in on the first physical terminal (yes, even if no monitor is connected) # run your code herefi - For an even more hacky work around (favoured by some) insert a suitable fixed length delay at the start of your code. Less than ideal as the same length won't work in all cases and it masks rather than fixes the problem.
[shameless self promotion]
Some further reading:
Autostart with labwc
Running A Program At Start UP A Beginner's Guide
Cron A Beginner's Guide
[/shameless self promotion]
Statistics: Posted by thagrol — Sat Dec 07, 2024 6:01 pm