2014-05-10 127 views
2

我在GTK窗口中使用VTE模塊來運行並顯示bash腳本的結果。Python Gtk2&Vte等待進程Pid完成

 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 

的問題是返回的是一次真正的,如果我寫一個循環,在bash腳本阻止。

+0

怎麼做你期望'當你在if語句檢查它pid'是。對不起,我真的不知道這個工具包,只是想幫助... – sshashank124

+0

我編輯了我的問題,但我不知道這是否是好方法。 Vte在Gtk窗口中放置一個終端,如Xterm,但集成了 – Guillaume

+0

我已閱讀此處http://stackoverflow.com/questions/10684180/python-checking-if-a-fork-process-is-finished但我不'知道它是否相同。我不明白代碼.. – Guillaume

回答

0

我已經找到了解決辦法:

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"