Reputation: 9714
In python multithreading (https://docs.python.org/3/library/threading.html#threading.Lock.acquire), the acquire allows lock to be non-blocking.
What is the purpose of making a non-blocking lock?
Upvotes: 0
Views: 199
Reputation: 882
When invoked with the blocking argument set to False, do not block. If a call with blocking set to True would block, return False immediately; otherwise, set the lock to locked and return True.
This makes it so you can attempt to acquire a lock, and if it is not free, do something else or simply continue execution.
if lock.acquire(blocking=False):
do_thread_unsafe_operation()
lock.release()
else:
do_something_else()
Upvotes: 2