The Python Way

Skip Montanaro skip at pobox.com
Wed Mar 27 19:37:25 EST 2002


I wrote that I should look at replacing code like this

    self.cache_lock.acquire()
    try:
        fiddle_some_cache...
    finally:
        self.cache_lock.release()

with code like this

    some_cache = self.some_cache_queue.get()
    fiddle_some_cache...
    self.some_cache_queue.put(some_cache)

I eventually realized I can avoid the try/finally however.  If something
happens within fiddle_some_cache... in the second code example I'd wind up
with an empty queue.  So, if I needed try/finally in the acquire/release
case, I will need it in the get/put case.  Silly me...

Skip





More information about the Python-list mailing list