Lock¶
-
class
Lock
(client, service_name, name)¶ Bases:
hazelcast.proxy.base.PartitionSpecificProxy
Distributed implementation of asyncio.Lock
-
force_unlock
()¶ Releases the lock regardless of the lock owner. It always successfully unlocks, never blocks, and returns immediately.
-
get_lock_count
()¶ Returns re-entrant lock hold count, regardless of lock ownership.
- Returns
(int), the lock hold count.
-
get_remaining_lease_time
()¶ Returns remaining lease time in milliseconds. If the lock is not locked then -1 will be returned.
- Returns
(long), remaining lease time in milliseconds.
-
is_locked
()¶ Returns whether this lock is locked or not.
- Returns
(bool),
true
if this lock is locked,false
otherwise.
-
is_locked_by_current_thread
()¶ Returns whether this lock is locked by current thread or not.
- Returns
(bool),
true
if this lock is locked by current thread,false
otherwise.
-
lock
(lease_time=-1)¶ Acquires the lock. If a lease time is specified, lock will be released after this lease time.
If the lock is not available, the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.
- Parameters
lease_time – (long), time to wait before releasing the lock (optional).
-
try_lock
(timeout=0, lease_time=-1)¶ Tries to acquire the lock. When the lock is not available,
If timeout is not provided, the current thread doesn’t wait and returns
false
immediately.If a timeout is provided, the current thread becomes disabled for thread scheduling purposes and lies
- dormant until one of the followings happens:
the lock is acquired by the current thread, or
the specified waiting time elapses.
If lease time is provided, lock will be released after this time elapses.
- Parameters
timeout – (long), maximum time in seconds to wait for the lock (optional).
lease_time – (long), time in seconds to wait before releasing the lock (optional).
- Returns
(bool),
true
if the lock was acquired and otherwise,false
.
-
unlock
()¶ Releases the lock.
-