Two processes into Zenity progress- how to auto close?

醉酒当歌 提交于 2020-01-25 07:28:20

问题


I have a dirty way to show upload speed while my Youtube API uploader script runs, I measure the network output of a specific port, while the upload is in progress. My problem is that the data from the network port continues after the upload so the Zenity progress remains open, and doesnt auto-close - can't figure out how to get around this. I require $upl to pass the youtube ID to another portion of the script, so I'm not sure I quite have that right. (Comments added for clarity)

#This is the uploading script
upl=$(python /home/pi/Documents/ytu/yt_up.py --file="${_file}" --title="$finaltitle $xy"  --description="$show_body" --keywords="$yt_tags" --category="28" --privacyStatus="$priv") | \
#This measures upload data rate $xy is the filename
ifstat -S -i eth0 |stdbuf -i0 -o0 -e0 tr '\r' '\n' |  stdbuf -i0 -o0 -e0 awk -W interactive '{print "#'$xy' " $2 "kb/s"}' | \
zenity --progress --width 500 --height 25 --title="Uploading to Youtube " \
                    --text="" --pulsate --auto-close --auto-kill

So my question is how to close the Zenity dialog on completion of the upload?


回答1:


It's not clear what is the upl value, and why is the assignment piped into ifstat. I'm assuming this is a typo, and there is no relationship between the ut_up.py and the progress monitoring, as per description, and that the upl is needed down the road.

Consider forking the zenity progress into the backgroud, BEFORE running the uploader. This will make it easier to transfer retain the value of the upl variable.

#
# Pre-fork the progress bar
#
ifstat -S -i eth0 |
  stdbuf -i0 -o0 -e0 tr '\r' '\n' |
  stdbuf -i0 -o0 -e0 awk -W interactive '{print "#'$xy' " $2 "kb/s"}' |
  zenity --progress --width 500 --height 25 --title="Uploading to Youtube " \
                    --text="" --pulsate --auto-close --auto-kill &
ZENITY_PID=$!

#
# Upload the data, save the result in `upl`
#
upl=$(python /home/pi/Documents/ytu/yt_up.py --file="${_file}" --title="$finaltitle $xy"  --description="$show_body" --keywords="$yt_tags" --category="28" --privacyStatus="$priv")

#
# Kill the progress bar (
#
kill $ZENITY_PID

To get the auto-close to work, you will need some way to send '100%' completion rate. This is complex in this case, as the upload process has to stay in the foreground (to set the upl variable. Additional information about the python script and the value of upl is needed to address this issue.



来源:https://stackoverflow.com/questions/59143763/two-processes-into-zenity-progress-how-to-auto-close

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!