Skip to content

Instantly share code, notes, and snippets.

@njsmith
Created November 21, 2018 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njsmith/736abbd76393c9ab9d0c189d9e0dc6d0 to your computer and use it in GitHub Desktop.
Save njsmith/736abbd76393c9ab9d0c189d9e0dc6d0 to your computer and use it in GitHub Desktop.
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