single thread decrement a semaphore object more than once?

birdsong david.birdsong at
Wed Feb 25 05:25:14 CET 2009

I searched but didn't see this already discussed, sorry if I didn't
search hard enough.

Can I decrement a semaphore's counter within the same thread more than
once?  I'd like to set hard and soft limits in a server I'm writing.
The server upon initialization would create a semaphore:


Then acquire 50x to hold half of the locks before serving any
requests.  This allows me to grow the number of locks to the hard
limit via signals or some other mechanism, but I need to know that any
1 thread has the ability to acquire up or release more than 1x and
effectively acquire and release for that number of semaphore values.

I could implement this by using regular threading.Lock in a pool, but
the Semaphore object would be much easier.

More information about the Python-list mailing list