[Python-Dev] PEP 340 -- concept clarification
Guido van Rossum
gvanrossum at gmail.com
Tue May 3 21:48:05 CEST 2005
[Tim]
> Because Queue does use condvars now instead of plain locks, I wouldn't
> approve of any gimmick purporting to hide the acquire/release's in
> put() or get(): that those are visible is necessary to seeing that
> the _condvar_ protocol is being followed ("must acquire() before
> wait(); must be acquire()'ed during notify(); no path should leave the
> condvar acquire()d 'for a long time' before a wait() or release()").
So you think that this would be obscure? A generic condition variable
use could look like this:
block locking(self.condvar):
while not self.items:
self.condvar.wait()
self.process(self.items)
self.items = []
instead of this:
self.condvar.acquire()
try:
while not self.items:
self.condvar.wait()
self.process(self.items)
self.items = []
finally:
self.condvar.release()
I find that the "block locking" version looks just fine; it makes the
scope of the condition variable quite clear despite not having any
explicit acquire() or release() calls (there are some abstracted away
in the wait() call too!).
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list