Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75343 > unrolled thread

Re: What happens when you 'break' a generator?

Started byJohannes Schneider <johannes.schneider@galileo-press.de>
First post2014-07-29 09:17 +0200
Last post2014-07-29 09:17 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: What happens when you 'break' a generator? Johannes Schneider <johannes.schneider@galileo-press.de> - 2014-07-29 09:17 +0200

#75343 — Re: What happens when you 'break' a generator?

FromJohannes Schneider <johannes.schneider@galileo-press.de>
Date2014-07-29 09:17 +0200
SubjectRe: What happens when you 'break' a generator?
Message-ID<mailman.12410.1406620022.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web