我使用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脚本就会阻塞。
发布于 2014-05-11 14:24:08
我找到了一个解决办法:
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"https://stackoverflow.com/questions/23581690
复制相似问题