terminal.py: avoid 100% cpu while waiting for phonehome pid file

Some of the less common terminal types haven't been tested with the
recent phonehome pid file changes and there may be error cases where
the pid file is never created.

(From OE-Core rev: 6b0cf568e9fbe28fb6e7b17f4ad92348d33e2bf4)

(From OE-Core rev: 9aa06b3116c095a512be1d1f5da84ffaedf845dc)

Signed-off-by: Andre McCurdy <armccurdy@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Andre McCurdy 2017-08-25 13:36:30 -07:00 committed by Richard Purdie
parent 0f81fcb600
commit 452164e7d6
1 changed files with 2 additions and 1 deletions

View File

@ -221,6 +221,7 @@ def spawn(name, sh_cmd, title=None, env=None, d=None):
# to a file using a "phonehome" wrapper script, then monitor the pid # to a file using a "phonehome" wrapper script, then monitor the pid
# until it exits. # until it exits.
import tempfile import tempfile
import time
pidfile = tempfile.NamedTemporaryFile(delete = False).name pidfile = tempfile.NamedTemporaryFile(delete = False).name
try: try:
sh_cmd = "oe-gnome-terminal-phonehome " + pidfile + " " + sh_cmd sh_cmd = "oe-gnome-terminal-phonehome " + pidfile + " " + sh_cmd
@ -232,13 +233,13 @@ def spawn(name, sh_cmd, title=None, env=None, d=None):
raise ExecutionError(sh_cmd, pipe.returncode, output) raise ExecutionError(sh_cmd, pipe.returncode, output)
while os.stat(pidfile).st_size <= 0: while os.stat(pidfile).st_size <= 0:
time.sleep(0.01)
continue continue
with open(pidfile, "r") as f: with open(pidfile, "r") as f:
pid = int(f.readline()) pid = int(f.readline())
finally: finally:
os.unlink(pidfile) os.unlink(pidfile)
import time
while True: while True:
try: try:
os.kill(pid, 0) os.kill(pid, 0)