Semaphore¶
- class dsviper.Semaphore¶
Bases:
objectA named semaphore, created or opened by name so that separate processes share it. Use the static factory method create(…) or open(…).
The object holds the handle and releases it when the object itself goes, so there is nothing to close. The name is a separate thing that no object owns: unlink(name) is what removes it, and a name left behind can outlive every process that used it. exists(name) answers whether one is there.
Note: Not directly instantiable.
- static exists(name: str) bool¶
Return True if a semaphore is already published under name.
- name() str¶
Return the name the semaphore is published under, which another process opens it by.
- post() bool¶
Release one, waking a waiter if there is one.
- try_wait() bool¶
Take one if the count is positive and return True; return False at once otherwise, without blocking.
- static unlink(name: str) bool¶
Remove the semaphore published under name.
- wait() bool¶
Block until the count is positive, then take one.
The wait holds the interpreter lock, so no other thread of this process runs to post: when the count is zero, the post that ends it comes from another process. To wait without blocking, poll try_wait() instead.