gpt4 book ai didi

Python Gtk2 & Vte 等待进程 Pid 完成

转载 作者:行者123 更新时间:2023-11-28 18:43:08 25 4
gpt4 key购买 nike

我在 GTK 窗口中使用 VTE 模块来运行和显示 bash 脚本的结果。

      adresse = self.champ.get_text()    
pid = self.v.fork_command(None, ['/bin/bash', "./pluzz.sh", adresse])

if pid == None: #pseudocode
print "Finish"

如果存在 time.sleep 或循环,则子进程处于阻塞状态(不运行)。我能怎么做 ?谢谢

编辑:试过这个:

def check_pid(pid):        
""" Check For the existence of a unix pid. """
try:
os.kill(pid, 0)
except OSError:
return False
else:
return True

问题是返回一次为 True,如果我写一个循环,bash 脚本就会阻塞。

最佳答案

我找到了一个解决方案:

def __init__(self):
a=0
self.fenetre = gtk.Window(gtk.WINDOW_TOPLEVEL)
[...]
self.v = vte.Terminal()
# self.v.connect ("child-exited", lambda term: gtk.main_quit()) # this is the line to change
self.v.connect ("child-exited", lambda term: self.copie(self, a)) # the redirection after the process is finish
self.v.show()

def download(self, a, donnees=None):
child_pid = self.v.fork_command(None, ['/bin/bash', "./pluzz.sh", adresse])

def copie(self, a, donnees=None):
print "FINISH"

关于Python Gtk2 & Vte 等待进程 Pid 完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23581690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com