fictive.patterns.concurrency module¶
Concurrency Primitives
Classes
provides some context-management features for an encapsulated lock |
|
Implements a spin lock around a nonblocking lock |
-
class
fictive.patterns.concurrency.ContextLock(lock)[source]¶ Bases:
objectprovides some context-management features for an encapsulated lock
-
exception
LockNotAcquiredError[source]¶ Bases:
Exceptionraised by a
protected function when the lock could not be acquired
-
acquire_context(blocking=True, timeout=- 1)[source]¶ a context manager that will attempt to acquire the lock
NB: if blocking is
Falseor timeout is > 0, make sure to check the returned value to determine whteher the lock was actually acquired. If aLockNotAcquiredErroris raised within the context, it will be handled by the context manager and the context will immediately cleanup and exit:lock = SpinLock(some_non_blocking_lock) with lock.acquire_context(timeout=5) as acquired: if not aquired: raise lock.LockNotAcquiredError() # lock is acquired do_something()
-
property
protect¶ returns a decorator that will acquire the lock before invoking the wrapped function
-
exception
-
class
fictive.patterns.concurrency.SpinLock(lock, spin_delay=None)[source]¶ Bases:
objectImplements a spin lock around a nonblocking lock
-
DEFAULT_SPIN_DELAY= 0.001¶
-
__init__(lock, spin_delay=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-