Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'friday,': 0.09; 'generators': 0.09; 'method,': 0.09; 'raises': 0.09; 'runtime': 0.09; 'throws': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '"with"': 0.16; 'cleanly': 0.16; 'coroutines': 0.16; 'effect.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'generator.': 0.16; 'guilty': 0.16; 'it;': 0.16; 'subject:generator': 0.16; 'wrote:': 0.18; 'properly': 0.19; 'cc:addr:python.org': 0.22; "shouldn't": 0.24; 'cc:2**0': 0.24; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; "we'd": 0.29; 'said,': 0.30; 'message- id:@mail.gmail.com': 0.30; 'usually': 0.31; '(on': 0.31; '13,': 0.31; 'about.': 0.31; 'terminate': 0.31; 'figure': 0.32; 'fri,': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'raising': 0.36; 'pm,': 0.38; 'that,': 0.38; 'expect': 0.39; 'does': 0.39; 'even': 0.60; 'worry': 0.60; 'march': 0.61; "you're": 0.61; 'discuss': 0.62; 'talking': 0.65; 'details': 0.65; 'close': 0.67; 'mar': 0.68; '2015': 0.84; 'confusing': 0.84; 'spoke': 0.91; 'whereas': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=6WLjtj7g/EmPeL5W+1N+pkHH+bA3yic0gYozyoa5Q/M=; b=Nj/lxgyImhmZgcQAofX+bkwNDMRhPNrwfg5NxA2BJg2nhQEy1+u2rb38JbLFa2CEA2 AgVotiXtQS7WI3Jnn1Jf6aNadpHAV1yC7QU7KpTJWd90tdmM/G9hK6/uhWOlrmjbmzBD YL4gIJ5HI+n2EzICCAuTxrfN37ZhfZtvaWgr48aX8y4XzE+4zoYxBIanwnbhptkg8J5P oUnUUd2KA3SWOj5pEZMYsOInKcYHXAylf4pbXe6+2wOw/JQy27uMClv+wrBQRt7TOFhe vUWNd6xda5eVviYF+e0ZdeL1EAIrgFy0HZrzK1VKaSDRx43WT2vhY4Bgg6HFTJyaAVYp S5qw== MIME-Version: 1.0 X-Received: by 10.50.9.97 with SMTP id y1mr43261213iga.34.1426246354991; Fri, 13 Mar 2015 04:32:34 -0700 (PDT) In-Reply-To: <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> Date: Fri, 13 Mar 2015 22:32:34 +1100 Subject: Re: generator/coroutine terminology From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1426246357 news.xs4all.nl 2949 [2001:888:2000:d::a6]:34094 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87367 On Fri, Mar 13, 2015 at 8:12 PM, Rustom Mody wrote: > On Friday, March 13, 2015 at 1:53:50 PM UTC+5:30, Chris Angelico wrote: >> On Fri, Mar 13, 2015 at 4:28 PM, Rustom Mody wrote: >> > And even there I would expect generators to close with StopIteration >> > Whereas I would expect coroutines to close (on close method) with GeneratorExit >> > [Ive not thought all this through properly so may be off the mark] >> >> I expect both of them to close with "return". > > Nice demo of the same confusing terminology we are talking about. > > When I say "expect generators to close" I mean 'generator-instances' ie at runtime > > When you say "expect both to close with return" you are talking of program-texts > ie the 'factory' > > [Or I am guilty of the same I am accusing python of] Well, if you're going to discuss the specifics of terminology, we'd best figure out what "close" means :) You spoke of generators closing "with" StopIteration. Does that mean that, once a generator closes, it raises StopIteration? That's the job of the next() method, in effect. Or do you mean that raising StopIteration will terminate the generator? That won't be true forever, and shouldn't be relied on - just use "return". If you use the close() method, Python throws a GeneratorExit into your generator. But unless you have something that catches that, you shouldn't need to worry about it; all you need to know is that you call close() and the function cleanly terminates. Like I said, there are implementation details that don't usually matter. ChrisA