PyDocs

Nav

Networking and Interprocess Communication

Semaphore

asyncio

class (source) not WASI
  • Semaphore(value=1)
A Semaphore implementation.

A semaphore manages an internal counter which is decremented by each
acquire() call and incremented by each release() call.  The counter
can never go below zero; when acquire() finds that it is zero, it
blocks, waiting until some other thread calls release().

Semaphores also support the context management protocol.

The optional argument gives the initial value for the internal
counter; it defaults to 1. If the value given is less than 0,
ValueError is raised.
Changed in 3.10
  • 3.10: Removed the loop parameter.
Members of Semaphore

a

acquire
Acquire a semaphore.

l

locked
Returns True if semaphore cannot be acquired immediately.

r

release
Release a semaphore, incrementing the internal counter by one.
0 Examples
No examples for asyncio/Semaphore.
See Also
No see-alsos for asyncio/Semaphore
0 Notes
No notes for Semaphore