简体   繁体   English

Python Gtk2和Vte等待进程Pid完成

[英]Python Gtk2 & Vte wait for the process Pid is finish

I'm using the VTE module in a GTK window, to run and show the result of a bash script. 我在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"

The child process is blocking (don't run) if there's time.sleep, or a loop. 如果有time.sleep或循环,则子进程阻塞(不运行)。 How can I do ? 我能怎么做 ? Thanks 谢谢

Edit: Tried this: 编辑:试过这个:

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

The problem is the return is once True, and if I write a loop, the bash script is blocking. 问题是返回一次是True,如果我写一个循环,bash脚本就会阻塞。

I've found a solution: 我找到了一个解决方案:

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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM