-
Notifications
You must be signed in to change notification settings - Fork 1
Hybrid Spin Semaphore API
mcyph edited this page Feb 4, 2020
·
2 revisions
Most applications won't need to use this class directly. To create a hybrid spin semaphore, you need to use the HybridLock constructor:
HybridLock(sem_loc, mode, initial_value, permissions)
mode
is one of:
-
CONNECT_OR_CREATE
: Connect to an existing semaphore if it exists, otherwise create one. -
CONNECT_TO_EXISTING
: Try to connect to an existing semaphore, raising anNoSuchSemaphore
if one couldn't be found by that name. -
CREATE_NEW_OVERWRITE
Create a new semaphore, destroying the existing one (if one does exist). -
CREATE_NEW_EXCLUSIVE
Create a new semaphore, raising aSemaphoreExists
exception if one already does.
initial_value
is the initial value of the semaphore (1 or 0 are the only
values possible). Note that this is only set if creating a new semaphore, this
value is otherwise ignored.
permissions
is who should be able to access the semaphore. For example, 0666
allows anyone to access the semaphore, whereas 0600 only allows the user who
created it (and root) to access it.
sem = HybridLock(
'test_location', CREATE_NEW_OVERWRITE, 1, 0666
)
sem.lock(timeout=1)
sem.unlock()
That's pretty much it - at the moment it only supports timeout values in seconds using whole integers.