Iterators and cleanup

John Arbash Meinel john at arbash-meinel.com
Fri Sep 22 20:55:44 BST 2006


Aaron Bentley wrote:
> In Python2.4, and earlier, you can't put a try/finally block in an
> iterator, and for good reason.  You don't know when or if they'll get
> cleaned up.
> 
> I was investigating #54000 [Nested progress bar not cleaned up on early
> exit].  And it should have been a red flag that
> iter_lines_added_or_present_in_versions was doing this:

...

> It seems like there are two ways to approach this.
> 1. Pass a progress bar into the iterator
> 2. Update the progress bar in the caller
> (fileids_altered_by_revision_ids).  That would seem to require the
> iterator to provide the expected total in some way.
> 
> Anyone else have insight into this one?
> 
> Aaron

I think you have a decent handle on it. I think (1) is the way to go.
And in the future, we should just realize that if you can't do a
'try/finally' then you shouldn't do it this way either.

I would guess that this doesn't happen very often elsewhere in the
codebase, or we would have problems more often.

John
=:->


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060922/801c30b2/attachment.pgp 


More information about the bazaar mailing list