问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/43466158/lock-acquirefalse-does