The Python Way

Andy Gimblett gimbo at ftech.net
Tue Apr 2 06:54:27 EST 2002


On Wed, Mar 27, 2002 at 03:01:56PM -0600, Skip Montanaro wrote:

>     self.cache_lock.acquire()
>     try:
>         fiddle_some_cache...
>     finally:
>         self.cache_lock.release()
> 
> would look a lot cleaner if I simply dumped the threading.RLock objects
> altogether and used Queue.Queue objects holding the cache:
> 
>     some_cache = self.some_cache_queue.get()
>     fiddle_some_cache...
>     self.some_cache_queue.put(some_cache)

I looked at the second code snippet, blinked, said "wow... nice!", but
then wondered if/why it's any better than the first, apart from the
already-mentioned cleanliness.  I _do_ like it, but it smells a bit
"clever", with perhaps a hint of implicity.  ;-)  Why's it better?

> Aahz is always admonishing us to just use Queue.Queue.  Maybe it's time
> I paid a bit closer attention to what he's been saying...

So, is Aahz/Tim saying that Queue.Queue is "better" in general than
threading.RLock ?  If so, why?  I'm honestly curious (though not
curiously honest, alas).

Cheers,

-Andy

-- 
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.




More information about the Python-list mailing list