TransWikia.com

Zenity Cancel button for GNU parallel progress bar

Unix & Linux Asked by ChameleonScales on October 31, 2021

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.

2 Answers

So apparently zenity wants a newline for Cancel to work.

GNU Parallel's --bar uses r in its output, which works great for the progress bar in zenity, but surprisingly not for the Cancel button.

One obvious solution is therefore to replace r with n before feeding it to zenity if you need the Cancel button:

seq 1000 |
  parallel -j30 --bar '(echo {}; sleep 0.1)' 2> >(perl -pe 'BEGIN{$/="r";$|=1};s/r/n/g' |
    zenity --progress --auto-kill) |
  wc

A less obvious solution is to use strace and trace for something that never happens:

seq 1000 |
  parallel -j30 --bar '(echo {};sleep 0.1)' 2> >(strace -e trace=creat zenity --progress --auto-kill) |
  wc

I have absolutely no idea why strace makes this work.

Answered by Ole Tange on October 31, 2021

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

Answered by Miloš Pavlović on October 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP