Created
November 21, 2018 23:16
-
-
Save njsmith/736abbd76393c9ab9d0c189d9e0dc6d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def communicate(self, stdin): | |
stdout = [] | |
stderr = [] | |
async def receive_all_into(pipe, buf): | |
while True: | |
data = await pipe.receive_some(LIMIT) | |
if not data: | |
break | |
buf.append(data) | |
async with trio.open_nursery() as nursery: | |
nursery.start_soon(receive_all_into, self.stdout, stdout) | |
nursery.start_soon(receive_all_into, self.stderr, stderr) | |
await self.stdin.send_all(stdin) | |
return (b"".join(stdout), b"".join(stderr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment