From 0f81fcb600e23006d5d459629c3562b8ee5a5a3f Mon Sep 17 00:00:00 2001 From: Leonardo Sandoval Date: Mon, 7 Aug 2017 12:21:51 -0700 Subject: terminal: wait for terminal task to finish before procedding This commit generalizes the work done in [1] and [2], both fixing issues on several areas (the former with -c patch and gnome-terminal and the latter with -c menuconfig and several terminals, including gnome-terminal and tmux). The main idea is to get the PID from the new spawned terminal and loop there until finished. [1] 76e8ab47c9: terminal: Fix gnome-terminal to work with recent versions [2] 7d02ea283b: cml1.bbclass: wait until menuconfig terminal finishes (From OE-Core rev: 55707401d5bfb1f7686c273fc2d0db89df206395) (From OE-Core rev: 3987dddff58410f1b2535ceb1f48aebbbd987889) Signed-off-by: Leonardo Sandoval Signed-off-by: Richard Purdie Signed-off-by: Armin Kuster Signed-off-by: Richard Purdie --- meta/lib/oe/terminal.py | 58 +++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'meta') diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py index 0426e15834..3c6220dfce 100644 --- a/meta/lib/oe/terminal.py +++ b/meta/lib/oe/terminal.py @@ -62,28 +62,7 @@ class Gnome(XTerminal): # Once fixed on the gnome-terminal project, this should be removed. if os.getenv('LC_ALL'): os.putenv('LC_ALL','') - # We need to know when the command completes but gnome-terminal gives us no way - # to do this. We therefore write the pid to a file using a "phonehome" wrapper - # script, then monitor the pid until it exits. Thanks gnome! - import tempfile - pidfile = tempfile.NamedTemporaryFile(delete = False).name - try: - sh_cmd = "oe-gnome-terminal-phonehome " + pidfile + " " + sh_cmd - XTerminal.__init__(self, sh_cmd, title, env, d) - while os.stat(pidfile).st_size <= 0: - continue - with open(pidfile, "r") as f: - pid = int(f.readline()) - finally: - os.unlink(pidfile) - - import time - while True: - try: - os.kill(pid, 0) - time.sleep(0.1) - except OSError: - return + XTerminal.__init__(self, sh_cmd, title, env, d) class Mate(XTerminal): command = 'mate-terminal -t "{title}" -x {command}' @@ -237,12 +216,35 @@ def spawn(name, sh_cmd, title=None, env=None, d=None): except KeyError: raise UnsupportedTerminal(name) - pipe = terminal(sh_cmd, title, env, d) - output = pipe.communicate()[0] - if output: - output = output.decode("utf-8") - if pipe.returncode != 0: - raise ExecutionError(sh_cmd, pipe.returncode, output) + # We need to know when the command completes but some terminals (at least + # gnome and tmux) gives us no way to do this. We therefore write the pid + # to a file using a "phonehome" wrapper script, then monitor the pid + # until it exits. + import tempfile + pidfile = tempfile.NamedTemporaryFile(delete = False).name + try: + sh_cmd = "oe-gnome-terminal-phonehome " + pidfile + " " + sh_cmd + pipe = terminal(sh_cmd, title, env, d) + output = pipe.communicate()[0] + if output: + output = output.decode("utf-8") + if pipe.returncode != 0: + raise ExecutionError(sh_cmd, pipe.returncode, output) + + while os.stat(pidfile).st_size <= 0: + continue + with open(pidfile, "r") as f: + pid = int(f.readline()) + finally: + os.unlink(pidfile) + + import time + while True: + try: + os.kill(pid, 0) + time.sleep(0.1) + except OSError: + return def check_tmux_pane_size(tmux): import subprocess as sub -- cgit v1.2.3-54-g00ecf