async def _read_proc_output(self, proc, timeout):
        """Read an async process' output until timeout is reached"""
        data = bytes()
        loop = asyncio.get_running_loop()
        start_time = loop.time()
        passed = loop.time() - start_time
        while passed < timeout:
            try:
                data += await asyncio.wait_for(
                    proc.stdout.readline(), timeout=timeout - passed
                )
            except asyncio.TimeoutError:
                pass
            passed = loop.time() - start_time
        return data
Read an async process' output until timeout is reached
tests/test_impersonate.py