[MERGE] Add exit() on progressbars from TestUIFactory

Robert Collins robert.collins at canonical.com
Tue Jun 9 08:28:26 BST 2009


On Mon, 2009-03-16 at 21:04 -0500, John Arbash Meinel wrote:
> Try to do that without fully consuming the generator.
> 
> do_a = a()
> print do_a.next()
> 
> 
> Note that we've only yielded 1 value, and then when we stop iterating
> the generator, none of the cleanup code gets called.
> 
> Python2.5 handles this by explicitly raising GeneratorExit when a
> generator is killed before it is fully consumed.
> 
> So *if* you always fully consume your generators, then try/except/else
> works for python2.4+.

Here is a tiny example:
>>> def f():
...  try:
...   yield 1
...  except:
...   print "except"
...  else:
...   print "else"
... 
>>> i=f()
>>> i.next()
1
>>> del i # note the lack of output
>>> i = f()
>>> i.next()
1
>>> i.next() # note that it prints else as expected
else
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
StopIteration
>>> 


Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20090609/f65e6204/attachment.pgp 


More information about the bazaar mailing list