livery.toolroom.store._exclusive¶
livery.toolroom.store._exclusive ¶
One process at a time through a section: an advisory lock on a file.
The kernel holds the lock for the open file and drops it when the
holder ends, however it ends. So a lock never outlives its holder, and
a waiter needs no stale bound and no timeout: it waits while a live
process works, however long the work takes. POSIX takes flock on
the whole file; Windows locks the file's first byte with
msvcrt.locking. Each is asked without blocking, and asked again
after POLL seconds, so the caller can say once that it waits.
The lock is per open file, not per process: two threads that each open the file exclude each other too.
Functions:
| Name | Description |
|---|---|
take_posix |
Take the lock on fd unless another holder has it; True when taken. |
give_posix |
Let go of the lock on fd. |
take_windows |
Take the lock on fd's first byte unless another holder has it. |
give_windows |
Let go of the lock on fd's first byte. |
exclusive |
Hold the lock on path while the block runs, waiting while another holds it. |
Attributes:
| Name | Type | Description |
|---|---|---|
POLL |
Seconds between two asks while another holder has the lock. |
take_posix ¶
Take the lock on fd unless another holder has it; True when taken.
Source code in packages/toolroom-store/src/livery/toolroom/store/_exclusive.py
give_posix ¶
take_windows ¶
Take the lock on fd's first byte unless another holder has it.
msvcrt.locking locks from the file's position, so the position
goes to the start first. The C runtime refuses a byte another
holder has locked with EACCES; any other error raises.
Source code in packages/toolroom-store/src/livery/toolroom/store/_exclusive.py
give_windows ¶
Let go of the lock on fd's first byte.
Source code in packages/toolroom-store/src/livery/toolroom/store/_exclusive.py
exclusive ¶
Hold the lock on path while the block runs, waiting while another holds it.
path is created when absent, and stays afterwards: a lock file removed while a process waits on it would let a third process take a lock on a new file of the same name. waiting is called once, the first time the lock is found held, so the caller can say what it waits for.