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

question about a persistent block #197

Closed
rhetr opened this issue Aug 5, 2016 · 8 comments
Closed

question about a persistent block #197

rhetr opened this issue Aug 5, 2016 · 8 comments

Comments

@rhetr
Copy link

rhetr commented Aug 5, 2016

I've been wanting a VU meter on my bar for a while and finally came across a solution using arecord.I got to writing this block

[vu]
command=arecord -vvv -D pulse_monitor 2>&1 /dev/null | gawk '/#/{ gsub("#","▮"); printf "{\"full_text\":\"%-20s‡\"}\n", $6 }'
interval=persist
format=json

which seems to be working fine except that it only updates every 10 or so seconds, whereas in the terminal it updates in milliseconds .

i wrote a test block to see how fast i can update a block and it seems to be working fine:

[test-ms]
command=while :; do date +'{"full_text": "%3N"}'; done
interval=persist
format=json

so I'm not entirely sure what the problem is.

@rhetr rhetr closed this as completed Aug 5, 2016
@rhetr rhetr reopened this Aug 6, 2016
@rhetr
Copy link
Author

rhetr commented Aug 6, 2016

reopened and changed issue

@rhetr rhetr changed the title fast-updating blocks? question about a persistent block Aug 6, 2016
@8carlosf
Copy link

8carlosf commented Aug 6, 2016

maybe it is a problem with the buffer on the stdout.. try disabling the buffer

https://serverfault.com/questions/294218/is-there-a-way-to-redirect-output-to-a-file-without-buffering-on-unix-linux/589614

@rhetr
Copy link
Author

rhetr commented Aug 6, 2016

yes! thanks. I added stdbuf -i0 -o0 -e0 in front of each command and now it works fine.

@rhetr rhetr closed this as completed Aug 6, 2016
@rhetr
Copy link
Author

rhetr commented Jul 30, 2020

not sure if i should open a new issue for this but i just upgraded to v1.5 (also upgraded from ubuntu 16.04 to ubuntu 20.04.1 lol) and now my vu meter keeps flashing. I routed stderr to /tmp/i3blocks.err and this is what I'm seeing:

<7>bar.c:bar_poll_readable:176: [vu-block] readable
<7>line.c:line_parse:65: &7:000: {"full_text":"▮▮▮▮▮▮▯▯▯▯▯▯▯▯▯▯▯▯▯▯"}
<7>block.c:block_update:146: [vu-block] updated successfully
...
<7>bar.c:bar_poll_readable:176: [vu-block] readable
<5>read(7, 1): Resource temporarily unavailable
<7>block.c:block_update:146: [vu-block] updated successfully
...
<7>bar.c:bar_poll_readable:176: [vu-block] readable
<7>line.c:line_parse:65: &7:000: {"full_text":"▮▮▮▮▮▮▮▮▮▯▯▯▯▯▯▯▯▯▯▯"}
<7>block.c:block_update:146: [vu-block] updated successfully
...
<7>bar.c:bar_poll_readable:176: [vu-block] readable
<5>read(7, 1): Resource temporarily unavailable
<7>block.c:block_update:146: [vu-block] updated successfully
...

Why does it keep saying 'resource temporarily unavailable'?

for reference here's the command:

 stdbuf -i0 -o0 -e0 arecord -vvv -B 80000 -D pulse_monitor 2>&1 /dev/null |
    stdbuf -i0 -o0 -e0 gawk '/#/{ gsub("#","▮"); printf "{\"full_text\":\"%-20s\"}\n", substr($6,2) }' |
    stdbuf -i0 -o0 -e0 sed 's/ /▯/g'

you add pulse_monitor to ~/.asoundrc, substituting the device with the one you want to monitor (you can view available sinks with pactl list sinks short):

pcm.pulse_monitor {
  type pulse
  device alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
}

ctl.pulse_monitor {
  type pulse
  device alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
}

@rhetr rhetr reopened this Jul 30, 2020
@zsugabubus
Copy link

Why does it keep saying 'resource temporarily unavailable'?

In a nutshell: because i3blocks’ read mechanism is flawed.

Using strace -fe write -s 50 ./your-command.sh >/dev/null reveals what’s going on (used “x” instead of boxes):

write(1, "{\"full_text\":\"xxxxxxxxxxxxxxxxxxxx\"}", 36) = 36
write(1, "\n", 1)           = 1

EOL is got written as a separate call.

Using stdbuf -oL everywhere fixes it, maybe it will be the solution to your issue too.

@rhetr
Copy link
Author

rhetr commented Jul 30, 2020

it works thanks! I tried PR 425 but was getting issues when used with this, but when I switched back to master it worked fine.

@rhetr rhetr closed this as completed Jul 30, 2020
@zsugabubus
Copy link

zsugabubus commented Jul 31, 2020

I can hardly believe that. Tried out just now and got the opposite results. Are you sure?

@rhetr
Copy link
Author

rhetr commented Jul 31, 2020

yep just tested zsugabubus/drain-stdout again with both -o0 and -oL options and neither worked. master works with -oL like you said.

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

3 participants