You are not logged in.

#1 2014-08-16 15:10:08

Ploppz
Member
Registered: 2013-09-14
Posts: 313

mpc idle player makes a resource-hungry loop if it throws errors.

In my panel script, to get music information:

while true; do
        mpc idle player >/dev/null
        #do things
done

This works well when there are no errors - every time something updates in mpd, my panel updates its information.

However, at the rare occation that mpd is down, mpc idle player throws an error, like "error: Connection refuses". This wakes mpc idle player instantly up from its wait and finishes the iteration, which repeats the process in an evil circle and causes a resource-hungry loop.

One solution I think, is to check if mpc throws an error, then sleep if it does. However, I'm unsure how to do that. $(mpc idle player) does indeed not output if the text is stderr, and I've run out of immediate ideas as I'm fairly nooby.
Thanks.

Offline

#2 2014-08-16 17:03:05

SahibBommelig
Member
From: Germany
Registered: 2010-05-28
Posts: 80

Re: mpc idle player makes a resource-hungry loop if it throws errors.

Check the $? variable. If it equals 0, continue. Else sleep(1) for a while and try again.

Offline

Board footer

Powered by FluxBB