[Python-ideas] The async API of the future: yield-from
Antoine Pitrou
solipsis at pitrou.net
Tue Oct 16 17:10:37 CEST 2012
On Tue, 16 Oct 2012 14:21:10 +0000
Steve Dower <Steve.Dower at microsoft.com> wrote:
> > It yields *and* returns, that's the way Guido's API works (as I understand it).
>
> I can't speak for Guido obviously, but you've certainly described what we came up with perfectly (http://pastebin.com/ndS53Cd8, the _Awaiter class starts on line 93).
>
> > # The real kicker here? Replace "yield wait_for_page" with
> > "wait_for_page.result()" and you have the equivalent
> > concurrent.futures code.
>
> Basically, the task/tasklet/async decorator aggregates the futures from inside the wrapped method and exposes a single future to the caller. Your example doesn't even need a scheduler or event loop, and we found that all the event loop was really doing was running the callbacks in a certain thread/context/equivalent.
I'm sure doing concurrent I/O will require an event loop, unless you
use threads under the hood...
Regards
Antoine.
--
Software development and contracting: http://pro.pitrou.net
More information about the Python-ideas
mailing list