3

I'm using the VTE module in a GTK window, to run and show the result of a bash script.

      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. 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.

Guillaume
  • 2,752
  • 5
  • 27
  • 42
  • What to do you expect `pid` to be when you are checking it in the if statement. Sorry I don't really know about this toolkit, just trying to help... – sshashank124 May 10 '14 at 13:40
  • I've edited my question, but I don't know if it's the good way. Vte fork a terminal in a Gtk window, like Xterm, but integrated – Guillaume May 10 '14 at 13:48
  • I have read here http://stackoverflow.com/questions/10684180/python-checking-if-a-fork-process-is-finished but I don't know if it's the same. I don't understand the code.. – Guillaume May 10 '14 at 13:54
  • Maybe: https://docs.python.org/2/library/os.html#os.waitpid Sorry I can't really be of much help – sshashank124 May 10 '14 at 13:55
  • Ok, thanks, I will read it. – Guillaume May 10 '14 at 14:01
  • I've seen this link http://stackoverflow.com/questions/7653178/wait-until-a-certain-process-knowing-the-pid-end but I can't use it – Guillaume May 10 '14 at 19:22

1 Answers1

1

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"
Guillaume
  • 2,752
  • 5
  • 27
  • 42