On 16.03.2015 13:02, Steven D'Aprano wrote: > (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.)
Just like with file-likes, it is useful to clean up resources. If you use a coroutine with the lxml.etree.xmlfile interface [1] for instance (code quoted from the reference): def writer(out_stream): with xmlfile(out_stream) as xf: with xf.element('{http://etherx.jabber.org/streams}stream'): try: while True: el = (yield) xf.write(el) xf.flush() except GeneratorExit: pass This allows controlled (i.e. not governed by garbage collection) and clean shutdown of a coroutine (albeit I’m not sure why they catch the GeneratorExit here), which will close the opened <stream> tag. regards, jwi [1]: http://lxml.de/api.html#incremental-xml-generation
signature.asc
Description: OpenPGP digital signature
-- https://mail.python.org/mailman/listinfo/python-list