def coprocess(self, directory=None): """Start a coprocess server. Return a CoProcess object that is the manager for the coprocess. Use the `start` method on that to actually run coprocess method. """ pid, conn = _fork_coprocess(directory) if pid == 0: # child sys.excepthook = sys.__excepthook__ proc = None signal.signal(signal.SIGCHLD, signal.SIG_DFL) self._procs = {} self._zombies = {} self.splitter = None atexit._run_exitfuncs() atexit._clear() sys.stdout.flush() sys.stderr.flush() _close_stdin() _redirect(1, "/tmp/devtest-coprocess-{}.stdout".format(os.getpid())) _redirect(2, "/tmp/devtest-coprocess-{}.stderr".format(os.getpid())) try: get_kernel().run(_coprocess_server_coro, conn) except KeyboardInterrupt: pass except: # noqa traceback.print_exc(file=sys.stderr) os._exit(0) else: proc = CoProcess(pid, conn) proc.progname = "CoProcess" self._procs[proc.pid] = proc logging.notice("ProcessManager: coprocess server with PID: {}".format(pid)) return proc
def _find_board_temp_file(self): """Find the thermal subystem temperature file to use for the board temperature. Use the THROTTLING-NOTIFY2 config. """ config_section = self._config.get("THROTTLING-NOTIFY2") if config_section is None: raise AndroidControllerError( "No THROTTLING-NOTIFY2 section in config") # Find the right thermal_zone path for that sensor type. sensor_type = config_section["sensor"] sensor_path = None ac = self._cont.adb.async_client async def match_entry(st, name): nonlocal sensor_path if stat.S_ISDIR(st.st_mode): if name.startswith("thermal_zone"): tpath = os.path.join(self.THERMAL_BASE, name, "type") out, err, es = await ac.command(["cat", tpath]) if es: if out.strip() == sensor_type: sensor_path = os.path.join(self.THERMAL_BASE, name, "temp") reactor.get_kernel().run(ac.list(self.THERMAL_BASE, match_entry)) return sensor_path
def start_process(cmd, delaytime=1.0, **kwargs): """Start a process and wait delaytime before returning. Gives spawned process a chance to initialize. """ proc = get_kernel().run(start_and_delay(cmd, delaytime, **kwargs)) get_manager().run_exit_handlers() return proc
def run_process(self, proc, timeout=None, input=None): """Take a Process instance and communicate with it. """ coro = _run_proc(proc, input) if timeout: coro = timeout_after(float(timeout), coro) output = get_kernel().run(coro) if isinstance(output, Exception): raise output return output
def call_command(self, cmd, directory=None): """Run command, does not collect output. Inherits main thread stdio. Returns an ExitStatus instance from command. """ proc = self.start(cmd, stdin=None, stdout=None, stderr=None, directory=directory) retcode = get_kernel().run(_call_proc(proc)) return exitstatus.ExitStatus(0, name=proc.progname, returncode=retcode)
def ping(self): """Verify server is running.""" return get_kernel().run(self.aping)
def close(self): get_kernel().run(self.aclose)
def delay(secs): return get_kernel().run(sleep(secs))
def _send_message(tag, data): kern = get_kernel() return kern.run(_send_message_coro(tag, data))
def write(self, data): kern = get_kernel() rv = kern.run(self.stdin.write(data)) kern.run(self.stdin.flush()) return rv
def readlines(self): return get_kernel().run(self.stdout.readlines())
def read(self, amt=-1): return get_kernel().run(self.stdout.read(amt))
def syncwait(self): return get_kernel().run(self._popen.wait())
def test_fdsignals(self): kern = reactor.get_kernel() kern.run(_signals_test_main)
def test_fdtimer(self): kern = reactor.get_kernel() kern.run(_timer_test_main)
def start(self, func, *args): """Start a method or function in the coprocess. """ return get_kernel().run(self.astart, func, args)
def run_coroutine(coro): return get_kernel().run(coro)
def wait(self): logging.debug("CoProcess: waiting on: {}".format(self.pid)) return get_kernel().run(self.a_wait)
def main(argv): pathname = argv[1] kern = reactor.get_kernel() return kern.run(adb_list, os.environ["ANDROID_SERIAL"], pathname)
def main(argv): kern = reactor.get_kernel() kern.run(adb_events, os.environ["ANDROID_SERIAL"])