[wmii] Re: multiple status/sleep instances in top

From: Jeremy Hankins <nowan_AT_nowan.org>
Date: Thu, 25 May 2006 11:49:07 -0400

mikshaw <mrblog_AT_yahoo.com> writes:
>>From Anselm R. Garbe:

>> Yes that is true, and in such scenario one needs to sleep after
>> the remove at least the same timeout, than refresh.
> Thank you. I had a notion that something like that would be needed,
> but I couldn't quite work out the logic of it. It seemed as though
> sleeping en extra 21+ seconds might not affect an existing instance
> of status, but it makes sense if the sleep occurs between removing
> the status label and recreating it.

It doesn't _always_ work. I have a status script with an interval set
to 20 minutes. It checks for active games on an online go server
(dragongoserver.net -- I'm happy to share the script if there're other
go players who use wmii).

If I run wmiirc twice within 20 minutes I'll get multiple instances of
the script if it's set up like the status script. To solve that
problem, here's what I use to do handle creation of the bar:

create_bar () {
    name="$1"; shift
    interval="$1"; shift

    wmiir remove /bar/$name 2>/dev/null && sleep $interval && sleep 1

    if wmiir read /bar/$name > /dev/null 2>&1; then
        return 1
        wmiir create /bar/$name
        xwrite /bar/$name/colors $color
        return 0

I then use it like this: ("warn" is a logging function.)

# Set $name, $interval, $color, and anything else here.

if create_bar $name $interval $color
then :
    warn "Couldn't create the bar \"$name\"; is another instance running? Aborting."
    exit 1

# Note that the existence of /bar/$name is checked both immediately
# before and immediately after the sleep. That ensures that it's
# checked at minimum every $interval (assuming that $interval is set
# longer than data collection could possibly take), so things get
# cleaned up.

while xread /bar/$name > /dev/null 2>&1; do

    # Do my (possibly lengthy and lag-ridden) data collection here.

    if [ -z "$result" ]; then
        xwrite /bar/$name/colors $DIM_BLUE
        xwrite /bar/$name/data " " || break
        xwrite /bar/$name/colors $ACT_RED
        xwrite /bar/$name/data "($name) $result" || break

    sleep $interval

Jeremy Hankins <nowan_AT_nowan.org>
PGP fingerprint: 748F 4D16 538E 75D6 8333  9E10 D212 B5ED 37D0 0A03
Received on Thu May 25 2006 - 17:49:19 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 16:06:49 UTC