vendredi 8 juillet 2016

button Stop/Cancel progressBar from subprocess PYGTK


I have been trying to add a cancel button to a progressbar en pygtk but now way to get the funcion. What its does that function is execute and script and every line in the output count it and is added to the progressBar. My problem is how to cancel that subprocess, is there a way? def stop(self, widget): print "cancelar" os.killpg(self.p.pid, signal.SIGTERM) #=> not working self.p.kill() #=> not working count = 0 command = "script.sh" self.p = subprocess.Popen(command, shell=True, bufsize=0, stdout=subprocess.PIPE, universal_newlines=True) for line in iter(self.p.stdout.readline, ""): count = count + 1 while gtk.events_pending(): gtk.mainiteration() gobject.timeout_add(1000, self.update) porcentaje = float(count) / float(1400) print porcentaje self.progress.set_text(str(int(porcentaje * 100)) + "%") self.progress.set_fraction(porcentaje)

Aucun commentaire:

Enregistrer un commentaire