generator/coroutine terminology

Marko Rauhamaa marko at pacujo.net
Mon Mar 16 08:42:30 EDT 2015


Steven D'Aprano <steve+comp.lang.python at pearwood.info>:

> (To be honest, I'm not even sure what the use-case for close() on
> coroutines is in the first place. If you don't want to send any more
> items into it, just don't send any more items into it.)

Without close(), you might leave resources hanging. See PEP 325:

    Rejected in favor of PEP 342 which includes substantially all of the
    requested behavior in a more refined form.

And PEP 342:

    Raymond Hettinger (PEP 288) and Samuele Pedroni (PEP 325) first
    formally proposed the ideas of communicating values or exceptions
    into generators, and the ability to "close" generators.

One *might* take the stance that resource allocation is outside the
scope of iterators, generator iterators and coroutine generator
iterators. As it stands, it is unclear if the application *must* call
close() on generator iterators that are left hanging.


Marko



More information about the Python-list mailing list