Synchronisation objects¶
Locks¶
Locks have been implemented to solve a distinct issue, most obvious when considering action tasks. During a long task, it may be necesarry to block any completing interaction with the LabThing hardware.
The labthings.StrictLock
class is a form of re-entrant lock. Once acquired by a thread, that thread can re-acquire the same lock. This means that other requests or actions will block, or timeout, but the action which acquired the lock is able to re-acquire it.
- class labthings.StrictLock(timeout: int = - 1, name: Optional[str] = None)
Class that behaves like a Python RLock, but with stricter timeout conditions and custom exceptions.
- Parameters
timeout (int) – Time in seconds acquisition will wait before raising an exception
- acquire(blocking: bool = True, timeout=<object object>, _strict: bool = True)
- Parameters
blocking – (Default value = True)
timeout – (Default value = sentinel)
_strict – (Default value = True)
A CompositeLock allows grouping multiple locks to be simultaneously acquired and released.
- class labthings.CompositeLock(locks, timeout: int = - 1)
Class that behaves like a
labthings.core.lock.StrictLock
, but allows multiple locks to be acquired and released.- Parameters
locks (list) – List of parent RLock objects
timeout (int) – Time in seconds acquisition will wait before raising an exception
- acquire(blocking: bool = True, timeout=<object object>)
- Parameters
blocking – (Default value = True)
timeout – (Default value = sentinel)
Per-Client events¶
- class labthings.ClientEvent
An event-signaller object with per-client setting and waiting.
A client can be any Greenlet or native Thread. This can be used, for example, to signal to clients that new data is available
- clear() bool
Clear frame event, once processed.
- set(timeout=5)
Signal that a new frame is available.
- Parameters
timeout – (Default value = 5)
- wait(timeout: int = 5)
Wait for the next data frame (invoked from each client’s thread).
- Parameters
timeout – int: (Default value = 5)