我在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
问题是return返回True,如果我写了一个循环,bash脚本就会阻塞。
答案 0 :(得分:1)
我找到了解决方案:
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"