Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75343
| Date | 2014-07-29 09:17 +0200 |
|---|---|
| From | Johannes Schneider <johannes.schneider@galileo-press.de> |
| Subject | Re: What happens when you 'break' a generator? |
| References | <lr7hsg$3pp$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12410.1406620022.18130.python-list@python.org> (permalink) |
On 29.07.2014 09:18, Frank Millman wrote: there's not print 'done' statement at the and. > Here I break the loop - > > x = test() > for j in x: > print(j) > if j == 2: > break > > Now the output is - > > start > 0 > 1 > 2 > > 'done' does not appear, so the generator does not actually terminate. What > happens to it? > > My guess is that normal scoping rules apply. Using my example, the generator > is referenced by 'x', so when 'x' goes out of scope, the generator is > garbage collected, even though it never completed. > > Is this correct? > > Frank Millman > > > -- Johannes Schneider Webentwicklung johannes.schneider@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: What happens when you 'break' a generator? Johannes Schneider <johannes.schneider@galileo-press.de> - 2014-07-29 09:17 +0200
csiph-web