def spawn(name, sh_cmd, title=None, env=None, d=None): """Spawn the specified terminal, by name""" logger.debug(1, 'Attempting to spawn terminal "%s"', name) try: terminal = Registry.registry[name] except KeyError: raise UnsupportedTerminal(name) pipe = terminal(sh_cmd, title, env, d) output = pipe.communicate()[0] if pipe.returncode != 0: raise ExecutionError(sh_cmd, pipe.returncode, output)
def spawn(name, sh_cmd, title=None, env=None, d=None): """Spawn the specified terminal, by name""" logger.debug(1, 'Attempting to spawn terminal "%s"', name) try: terminal = Registry.registry[name] except KeyError: raise UnsupportedTerminal(name) # 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 import time pidfile = tempfile.NamedTemporaryFile(delete=False).name try: sh_cmd = bb.utils.which( os.getenv('PATH'), "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: time.sleep(0.01) continue with open(pidfile, "r") as f: pid = int(f.readline()) finally: os.unlink(pidfile) # Test for /proc entry so that target pid can also be privileged procpid = "/proc/%d" % pid while True: try: os.stat(procpid) time.sleep(0.1) except OSError: return