, Gtk. , , . , , . "job_aborted" "", .
class MyWindow ...
def on_simulate(self, button):
self.job_aborted = False
args = self.makeargs()
gobject.idle_add(self.job_monitor(args).next)
def job_monitor(self, args):
self.state_running()
yield True
p = subprocess.Popen(args, stdout=subprocess.PIPE)
fd = p.stdout.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
while True:
if self.job_aborted:
os.kill(p.pid, signal.SIGTERM)
break
poll = p.poll()
if poll is not None:
break
try:
line = p.stdout.readline()
if line:
line = line.strip()
# update display
except IOError:
pass
yield True
self.state_ready() # re-enable controls
if self.job_aborted:
# user aborted
else:
# success!