resource
resource
#
lock — exclusive use of a machine-wide resource, such as the GPU, for a block.
- Wait.
lock(name)opens a log scope<name> lockand polls the resource's flock in the active scratch, updating the scope's message with who holds it and for how long (gpu lock: waiting for train (pid 4242), held 5m12s), so a page or terminal shows the wait. - Hold. Once acquired, the lock file names the holder — the purpose it
locked for, its pid and when — the scope's message becomes
<name> lock: heldand the scope stays open for the block, and the name is recorded in the context so a nestedlockof the same name, or apmapworker of the block, passes straight through instead of waiting on itself. - Release. The block's end, or its exception, releases the flock and closes the scope; the kernel releases it on any kind of death.
held_resources = ContextVar('cg_held_resources', default=(frozenset()))
module-attribute
#
The resources the current context holds; a nested lock of one passes through.
lock(name)
#
Hold the machine-wide resource name for the block, one holder at a time.
Holders are serialized across every thread and process sharing the active
scratch; the wait and the hold are a scope in the log, so a computing page
reads gpu lock: waiting for train (pid 4242), held 5m until the block
gets its turn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The resource, |
required |