Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lock.acquire(False) does?

Tags:

python

locking

I have a piece of code

    locked = lock.acquire(False)
        if locked:  break

according to python doc:
lock.aquire(False):- 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. I quite understand what they said but can somebody simplify this and please explain me in relation to the above code.

like image 270
Omniverse10 Avatar asked Jun 26 '26 06:06

Omniverse10


1 Answers

By default, lock.acquire will block execution of the thread until the lock is released by a different thread. If you pass block=False to the function (as in your example), the call will not block, and will return immediately. Its return value specifies whether or not your thread has actually acquired the lock.

like image 168
eyal Avatar answered Jun 28 '26 21:06

eyal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!