示例#1
0
    async def run(self):
        self.expected = getattr(self, "expected", None) or {"returncode": 0}
        if self.debug:
            fd_pipes = {}
            pr = None
            pw = None
        else:
            pr, pw = os.pipe()
            fd_pipes = {1: pw, 2: pw}
            pr = open(pr, "rb", 0)

        proc = AsyncFunction(
            scheduler=asyncio.get_event_loop(),
            target=self._subprocess,
            args=(self.args, self.cwd, self.env, self.expected, self.debug),
            fd_pipes=fd_pipes,
        )

        proc.start()
        if pw is not None:
            os.close(pw)

        await proc.async_wait()

        if pr is None:
            stdio = None
        else:
            stdio = await _reader(pr)

        self.result = {
            "stdio": stdio,
            "result": proc.result,
        }
示例#2
0
    def test_getpid_double_fork(self):
        """
		Verify that portage.getpid() cache is updated correctly after
		two forks.
		"""
        loop = asyncio._wrap_loop()
        proc = AsyncFunction(scheduler=loop, target=self._test_getpid_fork)
        proc.start()
        self.assertEqual(proc.wait(), 0)
示例#3
0
    def _test_getpid_fork(self):
        """
		Verify that portage.getpid() cache is updated in a forked child process.
		"""
        loop = asyncio._wrap_loop()
        proc = AsyncFunction(scheduler=loop, target=portage.getpid)
        proc.start()
        proc.wait()
        self.assertEqual(proc.pid, proc.result)
示例#4
0
 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)
示例#5
0
 async def _testAsyncFunctionStdin(self, loop):
     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:
         await _writer(pipe_write, test_string.encode("utf_8"))
     self.assertEqual((await 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()))