0

In i3blocks, I have defined a block like this:

~/.config/i3blocks/config:

[test]
interval=persist
format=json

The corresponding executable script: ~/.config/i3blocks/config.scripts/test:

#!/usr/bin/python

from time import sleep

while True: print("test") sleep(5)

I intend to replace "test" with an actual JSON-String later, I just stripped it down to this version for debugging purposes.

When I execute this on the command line, test gets printed to stdout every 5 seconds, as expected. I can get the PID with ps aux and check strace:

$ sudo strace -p82267 -s9999 -e write
strace: Process 82267 attached
write(1, "test\n", 5)                   = 5
write(1, "test\n", 5)                   = 5
[...]

ps aux also shows me the other process that i3blocks has started. strace with that process gives me no output, and I don't understand why. The loop seems to be running, but there is no stdout. To verify this, I removed the loop and restarted i3blocks, and the process is not listed anymore.

Why is there no stdout when i3blocks starts the process, and what can I do about that?

Edit:

I let it run for a long while and just noticed: strace shows me that a whole bunch of text was dumped to stdout all at once:

$ sudo strace -p79878 -s9999 -e write
strace: Process 79878 attached
--- SIGSTOP {si_signo=SIGSTOP, si_code=SI_USER, si_pid=79873, si_uid=1000} ---
--- stopped by SIGSTOP ---
--- SIGCONT {si_signo=SIGCONT, si_code=SI_USER, si_pid=79873, si_uid=1000} 
write(1, "test\ntest\n[...a big big block of output here...]test\ntest", 8194) = 8194

The SIGSTOP and SIGCONT also happened several times.

So it seems like the output is stored in some buffer for very long, and then dumped to stdout all at once at some point.

What can I do about that?

muru
  • 72,889
maddingl
  • 594

1 Answers1

0

Thanks to murus comment, I found the answer here:

If I change print("test") to print("test", flush=True), the output buffer gets flushed immediately after the print, which solves my issue.

maddingl
  • 594