[Python-Dev] Another threading idea

Paul Moore p.f.moore at gmail.com
Tue Mar 14 23:28:26 CET 2006


On 3/14/06, Guido van Rossum <guido at python.org> wrote:
> Isn't this a job for threading.BoundedSpemaphore()?

Not sure I see how. What I think Raymond's after (and certainly what I
want) is to queue N tasks, set a counter to N, then wait until the
counter goes to zero.

I suppose

    counter = Semaphore(-N)
    # Queue N tasks
    counter.acquire()

with each task (or the queue) saying

    counter.release()

when it finishes. But the logic seems backwards, and highly prone to
off-by-one errors, and I'm not entirely convinced that a negative
semaphore value is officially supported...

(BoundedSemaphore seems a red herring here - the blocking semantics of
Semaphore and BoundedSemaphore are identical).

Paul.


More information about the Python-Dev mailing list