[Python-ideas] asyncore: included batteries don't fit

Ben Darnell ben at bendarnell.com
Wed Oct 10 18:41:33 CEST 2012


On Tue, Oct 9, 2012 at 5:44 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> You might like to take a look at this, where I develop a series of
> examples culminating in a simple multi-threaded server:
>
> http://www.cosc.canterbury.ac.nz/greg.ewing/python/generators/yf_current/Examples/Scheduler/scheduler.txt


Thanks for this link, it was very helpful to see it all come together
from scratch.  And I think the most compelling thing about it is
something that I hadn't picked up on when I looked at "yield from"
before, that it naturally preserves the call stack for exception
handling.  That's a big deal, and may be worth the requirement of 3.3+
since the tricks we've used to get better exception handling in
earlier pythons have been pretty ugly.  On the other hand, it does
mean starting from scratch with a new asynchronous world that's not
directly compatible with the existing Twisted or Tornado ecosystems.

-Ben



>
> Code here:
>
> http://www.cosc.canterbury.ac.nz/greg.ewing/python/generators/yf_current/Examples/Scheduler/
>
>
>> somehow it seems there *has*
>> to be a distinction between an operation you just *yield* (this would
>> be waiting for a specific low-level I/O operation) and something you
>> use with yield-from, which returns a value through StopIteration.
>
> It may be worth noting that nothing in my server example uses 'yield'
> to send or receive values -- yield is only used without argument as
> a suspension point. But the functions containing the yields *are*
> called with yield-from and may return values via StopIteration.
>
> So I think there are (at least) two distinct ways of using generators,
> but the distinction isn't quite the one you're making. Rather, we
> have "coroutines" (don't yield values, do return values) and
> "iterators" (do yield values, don't return values).
>
> Moreover, it's *only* the "coroutine" variety that we need to cater
> for when designing an async event system. Does that help to
> alleviate any of your monad-induced headaches?
>
> --
> Greg
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas



More information about the Python-ideas mailing list