我有一个进程作为FIFO管道的一部分运行。
FIFO=$(mktemp -u)
mkfifo $FIFO
(cat $FIFO | zenity --progress \
--width 500 --height 25 --title="Uploading to Youtube " \
--text='<span font="12" font_weight="bold" foreground="red">'$xy'\n '"$fz"' Youtube Upload: '$fcount' TO GO </span>' --pulsate --auto-close --auto-kill) &
upl=$(python /home/pi/Documents/ytu/yt_up.py --file="${_file}" --title="$finaltitle $xy" --description="$show_body" --keywords="$yt_tags" --category="28" --privacyStatus="$priv")
echo 'Bye bye' > $FIFO
rm -f $FIFO目前这很好,在python脚本执行和关闭时,Zenity进度保持打开状态。但是,我希望能够使用cancel按钮中止进程,并在上面的代码之后尝试了这一点:
FIFO=$(mktemp -u)
mkfifo $FIFO
(cat $FIFO | zenity --progress \
--width 500 --height 25 --title="Uploading to Youtube " \
--text='<span font="12" font_weight="bold" foreground="red">'$xy'\n '"$fz"' Youtube Upload: '$fcount' TO GO </span>' --pulsate --auto-close --auto-kill) &
upl=$(python /home/pi/Documents/ytu/yt_up.py --file="${_file}" --title="$finaltitle $xy" --description="$show_body" --keywords="$yt_tags" --category="28" --privacyStatus="$priv")
#updated to show code I am using
if [ "$?" = 1 ] ; then
sudo pkill -f yt_up.py
fi
echo 'Bye bye' > $FIFO
rm -f $FIFO但是,Zenity进度对话框中的cancel按钮似乎不会触发pkill事件,也不会引发错误。在从CLI运行时,我已经测试了pkill代码是否工作,并关闭了脚本。
Update:我现在删除了FIFO以查看这是否有任何区别,也移到YAD,因为我可以精确地定位对话框窗口:
upl=$(python /home/pi/Documents/ytu/yt_up.py --file="${_file}" --title="$finaltitle $xy" --description="$show_body" --keywords="$yt_tags" --category="28" --privacyStatus="$priv") | \
yad --progress \
--button=Cancel:1 --geometry="500x125+138+40" --width=500 --height=25 --title="Uploading to Youtube " \
--text='<span font="12" font_weight="bold" foreground="red">'$xy'\n '"$fz"' Youtube Upload: '$fcount' TO GO </span>' --pulsate --auto-close
# Cancel from zenity progress bar
if [ "$?" = 1 ]; then
sudo pkill -f yt_up.py
echo "Dialog output=$?"
fi但是,python进程再次阻碍了对话输出。
发布于 2019-12-09 15:09:58
有两个进程正在运行,主main之一正在等待上传完成。考虑将代码组织成函数,以便更容易地控制行为。
当前代码在上载过程完成后检查状态。将始终表示成功,除非上传失败。从zenity状态检查新代码状态。
FIFO=$(mktemp -u)
mkfifo $FIFO
function progress {
cat $FIFO | zenity --progress \
--width 500 --height 25 --title="Uploading to Youtube " \
--text='<span font="12" font_weight="bold" foreground="red">'$xy'\n '"$fz"' Youtube Upload: '$fcount' TO GO </span>' --pulsate --auto-close --auto-kill
# Cancel from zenity progress bar
if [ $? = 1 ] ; then
pkill -f yt_up.py
fi
}
progress &
upl=$(python /home/pi/Documents/ytu/yt_up.py --file="${_file}" --title="$finaltitle $xy" --description="$show_body" --keywords="$yt_tags" --category="28" --privacyStatus="$priv")
#updated to show code I am using
echo 'Bye bye' > $FIFO
rm -f $FIFO无法测试-因为所需的部分不能共享。
https://stackoverflow.com/questions/59217281
复制相似问题