Shawn Walker wrote:
On 01/25/10 03:43 PM, Brock Pytlik wrote:
[email protected] wrote:
[snip]
line 1772: does this need to be wrapped with try:/finally:
activity_lock.release() in case enable_cancel fails?
This is a generator function. I didn't see a tidy way to wrap this in
another function with try/finally and have things work correctly.
It doesn't matter if it is a generator function. Python 2.5+
guarantees the finally bock will be executed:

http://docs.python.org/whatsnew/2.5.html

"...This last chance means that try...finally statements in
generators can now be guaranteed to work; the finally clause will
now always get a chance to run."

Or did I misunderstand the concern here?

That's part of the concern; however, the other part of the concern is
that there's no way to add another level of indendation to remote_search
without making the function unreadable. My other concern was how to
appropriately wrap the remote_search, a function that calls yield, with
another function that has the try/finally block and still retains the
functionality of a generator. I had thought that if I tried to iterate
over the response from remote_search and yield that instead, I would
pull all of the search results into memory.
Please, please don't pull all the results into memory. Besides causing a
potential explosion in memory usage, it also may cause a substantial
delay before the user begins to see results.

A generator of a generator will not cause the other generator to pull all of the results into memory, so this shouldn't be a concern.

I use generators of generators lots of places in catalog.py for this reason.

Never said a generator of generators would. However, if you iterate over the results, gather them in memory, then yield them one by one again, which is what I thought J was suggesting, that will cause an explosion in memory usage. Perhaps I misinterpreted what he wrote.

Brock
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss

Reply via email to