def _testAsyncFunctionStdin(self, loop=None): test_string = '1\n2\n3\n' pr, pw = os.pipe() fd_pipes = {0: pr} reader = AsyncFunction(scheduler=loop, fd_pipes=fd_pipes, target=self._read_from_stdin, args=(pw, )) reader.start() os.close(pr) _set_nonblocking(pw) with open(pw, mode='wb', buffering=0) as pipe_write: yield _writer(pipe_write, test_string.encode('utf_8'), loop=loop) self.assertEqual((yield reader.async_wait()), os.EX_OK) self.assertEqual(reader.result, test_string)
def async_main(fork_exitcode, loop=None): loop = asyncio._wrap_loop(loop) proc = AsyncFunction(scheduler=loop, target=fork_main) proc.start() proc.async_wait().add_done_callback( lambda future: fork_exitcode.set_result(future.result()))