[Python-ideas] Hooks into the IO system to intercept raw file reads/writes

Paul Moore p.f.moore at gmail.com
Mon Feb 2 19:28:58 CET 2015


On 2 February 2015 at 17:47, Guido van Rossum <guido at python.org> wrote:
> Perhaps you would be better off using the subprocess machinery in asyncio?
> It uses the subprocess module to manage the subprocess itself (both for
> Windows and for Unix-ish systems) but uses the async I/O machinery from the
> asyncio module (which is itself based on select or its better brethren).

Quite possibly. I found the asyncio docs a bit of a struggle, TBH. Is
there a tutorial? The basic idea is something along the lines of
https://docs.python.org/3.4/library/asyncio-subprocess.html#subprocess-using-streams
but I don't see how I'd modify that code (specifically the "yield from
proc.stdout.readline()" bit) to get output from either stdout or
stderr, whichever was ready first (and handle the 2 cases
differently).

I don't know whether event-based behaviour makes more sense to me than
the corioutine-based approach used by the asyncio documentation. OTOH,
the alternative protocol-based approach didn't seem to have an event
for data received on stderr, just the one for stdout. So maybe it's
not just the approach that's confusing me.

Paul


More information about the Python-ideas mailing list