Iterators and cleanup

Aaron Bentley aaron.bentley at utoronto.ca
Fri Sep 22 20:49:10 BST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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:

        try:
            ...
            yield line
            ...
            pb.update('Walking content.', total, total)
            pb.finished()
        except:
            pb.update('Walking content.', total, total)
            pb.finished()
            raise

It's clearly supposed to be like a try/finally block.  But you can't
wrap a try/finally around a yield.  Because an exception could fire
outside the iterator, and then the cleanup would never happen.

And that seems to be why pull doesn't clean up its progress bars correctly.

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

https://launchpad.net/products/bzr/+bug/54000
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFFFD420F+nu1YWqI0RAjZVAKCGSS4wex98V+unRlkuGKW91HpeXgCfYaUB
wYWvAVPE7J16t7jD353eMiE=
=CXoN
-----END PGP SIGNATURE-----




More information about the bazaar mailing list