[MERGE] Add exit() on progressbars from TestUIFactory

Martin Pool mbp at sourcefrog.net
Tue Mar 17 01:26:32 GMT 2009

Thanks for the review.

Although the code is correct, I'm not sure on further consideration
whether it's really the best way to handle progress from inside

Firstly, I saw in some existing code that while you cannot do
try/finally in python2.4, you apparently can do

except e:

... which is so close to try/finally one really wonders why they
thought it was impossible, but anyhow.  It does mean that you cannot
just 'return' from inside the try block to finish the function, but
rather you have to arrange to exit it through the bottom, and there is
some risk of a bug if you forget to do so.

This has the advantage that all the code to do with the pb is inside
the generator function.

But even beyond that, the thing is that most generators end up being
consumed by a regular non-generator function, and it may avoid the
whole issue to just do progress from the consumer rather than the
producer.  This would take some special handling though for cases
where the generator is passed into a list or otherwise fully exhausted
before its results are used but that's not so bad.

Anyhow, I'll probably merge this, but I may pull it out when I try to
clean up some of the places that use it.

Martin <http://launchpad.net/~mbp/>

More information about the bazaar mailing list