Semaphore¶
from acron.core import Semaphore
- class Semaphore¶
Bases:
A classic semaphore synchronization primitive.
A semaphore manages an internal counter which is decremented by each
acquire()call and incremented by eachrelease()call. The counter can never go below zero; whenacquire()finds that it is zero, it blocks, waiting until some other thread callsrelease().Inheritance diagram
digraph inheritance150e5dddaa { bgcolor=transparent; rankdir=BT; size="8.0, 12.0"; "DTOOL_SUPER_BASE" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style=""]; "Semaphore" [URL="acron.core.Semaphore.html#acron.core.Semaphore",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "Semaphore" [arrowsize=0.75,style=""]; }- __init__()¶
- acquire()¶
Decrements the internal count. If the count was already at zero, blocks until the count is nonzero, then decrements it.
- get_count()¶
Returns the current semaphore count. Note that this call is not thread- safe (the count may change at any time).
- output()¶
- release()¶
Increments the semaphore’s internal count. This may wake up another thread blocked on
acquire().Returns the count of the semaphore upon release.
- try_acquire()¶
If the semaphore can be acquired without blocking, does so and returns true. Otherwise, returns false.