shdown / luastatus

universal status bar content generator
GNU General Public License v3.0
293 stars 12 forks source link

io.popen causing luastatus to hang #71

Open intr-cx opened 1 year ago

intr-cx commented 1 year ago

I've been trying to write a widget for displaying the amount of new unread emails. It successfully calculates the number of new mail, but when running it with the lemonbar wrapper and other widgets like cpu-temperature (which also invokes io.popen) the bar will freeze and no longer update. Here's the script in question;

widget = {
    plugin = 'inotify',
    opts = {
        watch = { [os.getenv("HOME") .. "/.config/mutt/.mailsynclastrun"] = { "attrib" } },
        greet = true
    },
    cb = function()
        local pp = assert(io.popen([[/usr/bin/find /home/intr/.local/share/mail/*/[Ii][Nn][Bb][Oo][Xx]/new/* -type f | wc -l]], 'r'))
        m = pp:read("*a")
        pp:close()
        return ' ' .. m
    end
}

Strangely, the same thing happens when trying to use the bluetooth example widget. I'm positive that io.popen is the function causing it to hang, as I've added a boatload of print statements to narrow it down. I'm not a lua dev by any means, but I'd love to get this to work. Googling has brought me basically nowhere, so I was wondering if you could explain what I'm doing wrong (or if it's some sort of bug in luastatus.) Thanks in advance.

shdown commented 1 year ago

Does it also hang if you replace [[/usr/bin/find /home/intr/.local/share/mail/*/[Ii][Nn][Bb][Oo][Xx]/new/* -type f | wc -l]] with echo test?

What versions of Lua, luastatus and lemonbar are you using?

shdown commented 1 year ago

Can you please add io.stderr:write('cb called\n') to the beginning of cb?

Can you run luastatus under strace -f (LUASTATUS="strace -f luastatus" luastatus-lemonbar-launcher …) and paste the full output?

shdown commented 1 year ago

Anyway, I can’t reproduce it here with /tmp/luastatus-test as the file to be watched and the command replaced to date +%s.%N.

intr-cx commented 1 year ago

@shdown Thanks for your reply. The issue seems to happen when using both the cpu-temperature widget (which also uses io.popen) and the mail widget (same with the bluetooth widget.) Below is the output from strace. Perhaps it's related to concurrent calls to popen?

out.txt

shdown commented 1 year ago

What versions of Lua, luastatus and lemonbar are you using?

Does it also hang if you replace [[/usr/bin/find /home/intr/.local/share/mail/*/[Ii][Nn][Bb][Oo][Xx]/new/* -type f | wc -l]] with 'date +%s.%N'?

Can you please add io.stderr:write('cb called\n') to the beginning of cb and io.stderr:write('popen done\n') after popen?

intr-cx commented 1 year ago

Sorry! I forgot to mention those details.

Replacing popen with the date command will spawn the bar showing the date, everything remains responsive until I touch the mailsynclastrun file.

I have also tried switching from the inotify plugin to a simple timer, which will also hang after the second time cb is called.

Adding the io.stderr:write before & after popen will print the first error as follows;

luastatus: error: (lua) mail.lua:8: attempt to call field 'stderr' (a userdata value)
stack traceback:
        mail.lua:8: in function <mail.lua:7>
intr-cx commented 1 year ago

I've also tried different variants of luastatus & lemonbar, namely the vanilla variants without any patches, but the result remains the same.

One thing I noticed is that it's only cpu and mem which end up freezing, the rest (bspwm, pulse, date/time) remains active. Any help would still be appreciated.