簡體   English   中英

Python Gtk2和Vte等待進程Pid完成

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

我在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"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM