dragon.mpbridge.synchronize.DragonRLock
- class DragonRLock
Bases:
AugmentedDragonNativeLock
A recursive lock co-located on the same node by default as the creating process
- __init__(*args, ctx, **kwargs)
Initialize the lock object
Methods
__init__
(*args, ctx, **kwargs)Initialize the lock object
acquire
([block, timeout])Acquire a lock, blocking or non-blocking.
count
()How often this lock has been acquired.
is_mine
()Return True if this rlock is owned by the caller process & thread
Return True if this lock is recursive, i.e. can be called multiple times by the same thread/process.
release
()Release a lock.
- __init__(*args, ctx, **kwargs)
Initialize the lock object
- acquire(block: bool = True, timeout: float = None) bool
Acquire a lock, blocking or non-blocking.
If the lock is not recursive:
With the block argument set to True (the default), the method call will block until the lock is in an unlocked state, then set it to locked and return True.
With the block argument set to False, the method call does not block. If the lock is currently in a locked state, return False; otherwise set the lock to a locked state and return True. When invoked with a positive, floating-point value for timeout, block for at most the number of seconds specified by timeout as long as the lock can not be acquired. Invocations with a negative value for timeout are equivalent to a timeout of zero. Invocations with a timeout value of None (the default) set the timeout period to infinite. The timeout argument has no practical implications if the block argument is set to False and is thus ignored. Returns True if the lock has been acquired or False if the timeout period has elapsed.
If the lock is recursive, repeated calls to a lock already owned by the current process return True and increment the recursion level.
Release()
has then be called an equal amount of times by the same process to free the lock.
- count() int
How often this lock has been acquired. Will return only 0 or 1 for a non-recursive Lock. :return: The number of times this lock has been acquired :rtype: int
- is_mine() bool
Return True if this rlock is owned by the caller process & thread
- Returns:
ownership of the lock
- Return type:
- is_recursive() bool
Return True if this lock is recursive, i.e. can be called multiple times by the same thread/process.
- Returns:
recursiveness of the lock
- Return type:
- release() None
Release a lock.
If the lock is not recursive: This can be called from any process or thread, not only the process or thread which originally acquired the lock.
If the lock is recursive: Decrement the recursion level. If after the decrement the recursion level is zero, reset the lock to unlocked (not owned by any process or thread) and if any other processes or threads are blocked waiting for the lock to become unlocked, allow exactly one of them to proceed. If after the decrement the recursion level is still nonzero, the lock remains locked and owned by the calling dragon process and thread.
- Raises:
ValueError – if the lock has not been acquired before
AssertionError – if the lock is recursive and not held by the caller