Lock.acquire(False) does?

孤者浪人 提交于 2020-01-02 22:01:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!