Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.popen causing luastatus to hang #71

Open
intr-cx opened this issue Mar 31, 2023 · 7 comments
Open

io.popen causing luastatus to hang #71

intr-cx opened this issue Mar 31, 2023 · 7 comments

Comments

@intr-cx
Copy link

intr-cx commented Mar 31, 2023

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
Copy link
Owner

shdown commented Apr 1, 2023

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
Copy link
Owner

shdown commented Apr 1, 2023

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
Copy link
Owner

shdown commented Apr 1, 2023

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
Copy link
Author

intr-cx commented Apr 1, 2023

@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
Copy link
Owner

shdown commented Apr 2, 2023

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
Copy link
Author

intr-cx commented Apr 2, 2023

Sorry! I forgot to mention those details.

  • luastatus-luajit-git from the AUR, r773.8d01bdf-2
  • lemonbar-ucs4-git from the AUR, 213.91b444a-1
  • Lua 5.4.4

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
Copy link
Author

intr-cx commented Apr 18, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants