[Python-ideas] More general "for" loop handling
Stefan Behnel
stefan_ml at behnel.de
Fri May 1 13:58:29 CEST 2015
Guido van Rossum schrieb am 30.04.2015 um 19:31:
> But 'async for' is not meant to introduce parallelism or concurrency.
Well, the fact that it's not *meant* for that doesn't mean you can't use it
for that. It allows an iterator (name it coroutine if you want) to suspend
and return control to the outer caller to wait for the next item. What the
caller does in order to get that item is completely up to itself. It could
be called "asyncio" and do some I/O in order to get data, but it can
equally well be a multi-threading setup that grabs data from a queue
connected to a pool of threads.
Granted, this implies an inversion of control in that it's the caller that
provides the thread-pool and not the user, but it's not like it's
unprecedented to work with a 'global' pool of pre-instantiated threads (or
processes, for that matter) in order to avoid startup overhead.
Stefan
More information about the Python-ideas
mailing list