Zenity – Cancel Button for GNU Parallel Progress Bar

bashgnu-parallelio-redirectionprocess-substitutionzenity

As GNU parallel's manual shows, you can use a zenity progress bar with parallel:

seq 1000 | parallel -j30 --bar '(echo {};sleep 0.1)' \
    2> >(zenity --progress --auto-kill) | wc

However, in that example, the cancel button doesn't work. I've read about similar issues with this button when used with more usual commands (i.e. not parallel) as well as some more insight about how that cancel button works but that didn't really help me. Parallel seems to make use of it quite differently and I can't figure out how to get that cancel button to stop the process.

I'm mostly confused by the 2> > and the wc. If I just use a | instead, the cancel button works but now the progress bar goes faster and finishes too early (I guess it only shows the progress of the first split part of the job? But if that was the case it should be 30 times faster, which it's not, so I'm not sure).

PS: Just to let you know, I've told about this issue on the parallel mailing list.

Best Answer

Zenity is desinged to read two lines, one for progress bar and one begining with "#" for progress text:

for ((i=0;i<=100;i++));do
  echo "$i"                  # bar
  echo "#percent done $i"    # text
  sleep .1
done
| zenity --progress

I guess that --bar option writes progress to stderr but doesn't close it or doesn't write a newline character at the end of the line. That blocks zenity which expects a new line. The workaround is to print newline to stderr which is file descriptor 2 by default.

seq 1000 | parallel -j30 --bar '(echo {}; echo >&2; sleep 0.1)' \
    2> >(zenity --progress --auto-kill) | wc
Related Question