Coroutines: unexpected behaviour
Jérôme Mainka
jmainka at gmail.com
Wed Jun 16 12:51:28 EDT 2010
On Jun 16, 6:35 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> How bizarre is that?
Sure...
> I have to say that your code is horribly opaque and unclear to me.
Welcome to the coroutines world :-)
This is mainly a pipeline where each function suspends execution
waiting for data (yield), and feeding other functions (the sort
function's target argument) with data (.send())
-> sort() -> dump()
> Because yield will often be returning None, you should always check for
> this case. Don't just use its value in expressions unless you're sure
> that the send() method will be the only method used resume your generator
> function.
This remark deals with constructions like:
value = (yield i)
For an excellent introduction to coroutines in python, I recommend:
http://www.dabeaz.com/coroutines/
Thanks,
Jérôme
More information about the Python-list
mailing list