2014-05-10 4 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

는'pid' 될 수 있습니다. 죄송합니다.이 툴킷에 대해 잘 모르는 중입니다. – sshashank124

+0

내 질문을 편집했지만 좋은 방법인지는 모르겠습니다. Vte는 Xterm과 같은 Gtk 윈도우에서 터미널을 포크 화합니다. – Guillaume

+0

여기를 읽었습니다. http://stackoverflow.com/questions/10684180/python-checking-if-a-fork-process-is-finished하지만 저는 ' 똑같은지 알지 못한다. 코드를 이해할 수 없습니다. – Guillaume

답변

0

나는 해결책을 발견했습니다 당신은 if 문에서 확인 할 때 예상해야 할 일

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"