python asyncio - 2. Subprocess
asyncio.create_subprocess_exec() and asyncio.create_subprocess_shell() are the async counterparty of subprocess.Popen in the multi-process world.
For each subprocess, it creates a thread to watch it. Basically, this watching thread will block at os.watchpid() until the subprocess exits. When it happens, the watching thread calls a callback, and this callback just call asyncio.Future.set_result().
This post is licensed under CC BY 4.0 by the author.