def _consume_in_subprocess(self, job, kwargs): params = dict(self.json_params()) loop = job._loop transport, protocol = yield from loop.subprocess_exec( lambda: StreamProtocol(job), sys.executable, PROCESS_FILE, json.dumps(sys.path), json.dumps(params), job.task.serialise()) process = Process(transport, protocol, loop) yield from process.communicate() if job.task.stacktrace: raise RemoteStackTrace return job.task.result
async def wait_for_child_process(child: Process, timeout: int) -> Tuple[bytes, int, bool]: try: output, _ = await asyncio.wait_for(child.communicate(), timeout=timeout) timed_out = False returncode = child.returncode if child.returncode else 0 except asyncio.TimeoutError: timed_out = True returncode = -9 try: child.terminate() # Give mpiexec a chance to shutdown except ProcessLookupError: pass output, _ = await child.communicate() return output, returncode, timed_out