Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '[1]:': 0.09; 'try:': 0.09; 'def': 0.12; '(code': 0.16; 'coroutines': 0.16; 'filename:fname piece:signature': 0.16; 'garbage': 0.16; 'governed': 0.16; 'i\xe2\x80\x99m': 0.16; 'quoted': 0.16; 'received:10.13': 0.16; 'subject:generator': 0.16; 'true:': 0.16; 'wrote:': 0.18; 'header :User-Agent:1': 0.23; 'pass': 0.26; 'subject:/': 0.26; 'header:In- Reply-To:1': 0.27; '[1]': 0.29; "i'm": 0.30; 'controlled': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'allows': 0.31; 'interface': 0.32; '(i.e.': 0.33; 'except': 0.35; 'useful': 0.36; 'url:org': 0.36; 'received:10': 0.37; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; 'even': 0.60; 'catch': 0.60; 'first': 0.61; 'more': 0.64; 'close': 0.67; 'shutdown': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wielicki.name; s=k001.sol; t=1426509569; bh=kPN2gbWJGRxM73nxBkFIJKRCoewuoYR+Ed0Sjj+BKFA=; h=Date:From:To:Subject:References:In-Reply-To; b=gG4fhKdnFe6zjlv7AsB3PE4dfPHhnJL8i0e6AzCBZUXir4ylNE1Sz1I4+JUY2e/mA iAwEhwC9LyzOys/iemOGRWqJ9ps1ArsRwQwj0aM+90LvgQcVa6GlJ/NDBX4iMR2Voj R+nK2HkozJWfL69llBi7MsqHQQBiTq+OexhvjW7IB93PLaXM0y/jRJwUFCFCpwXenA 0PEZpu9f5xfs8qovoA4Scc4texiMS1Hp72PPImRlSoHOLjA1sy8gR4tG0aq0dBO8kE WbI3sX4oHaNOE0hlXH2nsb0bk69Qs5aF32t9MubK0g+Gx8J9n9+8PpzkrSQ3YwDgsC cZO0o1bm7ClPQ== Date: Mon, 16 Mar 2015 13:39:18 +0100 From: Jonas Wielicki User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: generator/coroutine terminology References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <874mpnp6nv.fsf@elektro.pacujo.net> <87y4mznmj8.fsf@elektro.pacujo.net> <55062bda$0$12998$c3e8da3$5496439d@news.astraweb.com> <87egopmn4z.fsf@elektro.pacujo.net> <8761a1mlaz.fsf@elektro.pacujo.net> <5506c65c$0$13000$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <5506c65c$0$13000$c3e8da3$5496439d@news.astraweb.com> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="V4R1MDgIJwg6hNJ2N8awEHvICA6ACpsrS" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 66 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1426510175 news.xs4all.nl 2891 [2001:888:2000:d::a6]:32921 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87549 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --V4R1MDgIJwg6hNJ2N8awEHvICA6ACpsrS Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 corou= tines > 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 =3D (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=E2=80=99m not sure why they catch= the GeneratorExit here), which will close the opened tag. regards, jwi [1]: http://lxml.de/api.html#incremental-xml-generation --V4R1MDgIJwg6hNJ2N8awEHvICA6ACpsrS Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJVBs7+AAoJEMBiAyWXYliKUjIP/0YroXIDPpAUCtlsM4Z2BLNz VVCc4ZqcOKgfam+sbFVsLpIWy0yf6Ca8dvIRONgyB370XsKVbmaqLey5lLL6b+RF MvDmB2IQvO1iQkp2389rO9m8H8kBbs4B4ZEhfpsIvoQiDdXdvtIXcU3LYdeVP3G6 AVhaEEefihHDS3/xi7uf4faGb9TZJVMTkIbRVboEiI9rRpOv84xxINqM0Y+8S0zo g5WSLLs5xKOurhTZ+7sUi/Imxy7Gl5WnKeQtGrBwlQbCSbmeUjPl2NmWQCW1isYl 33NsEg0Hwzn2gdEFzWXEIeEEew7sbwUHvc3CHRaC9bGzCKUg03h1Vi0Xy8Hn0dz7 37ZbkkR8uf6H0eGtMpG5ZgN7BPLODrWhPzbmMXvzSd9lO9w6+FADpWk+zHArOVm2 wSJHNC2L9Jun3+CWeFSLWx+uvvP2zNiw18dKD4jF2NDzS3UKLfM8OVNf90ORS+28 4jKrY72lVUP7MBjE8vnnxBQSoL0Dj08BVqlUT/3zCh4EwSXz2MBClhUih8BQN4K3 5Hn/xZQI8D3dSvHG/5IzNBzNeZAOXYsIeuqWIjazrrQEFabMr7L79kwH93fJAO/i xJOMV17CNsNg/8rRP9Cve9h0aIon0W9A8fEX6GKnJ1W9H/t6e4+2bdehbciTnjg4 Qcm5YVWQrJiBwrYGLAV+ =ttCP -----END PGP SIGNATURE----- --V4R1MDgIJwg6hNJ2N8awEHvICA6ACpsrS--