tornado.locks.Lock发布(tornado.locks.Lock release)
龙卷风示例给出了以下锁的示例:
>>> from tornado import gen, locks >>> lock = locks.Lock() >>> >>> @gen.coroutine ... def f(): ... with (yield lock.acquire()): ... # Do something holding the lock. ... pass ... ... # Now the lock is released.
你是否需要在使用之后手动释放锁定,或者是否在该块中使用with语句? 如果是这种情况,为什么有一个单独的release()并且需要产生这个函数?
The tornado example gives the following example for locks:
>>> from tornado import gen, locks >>> lock = locks.Lock() >>> >>> @gen.coroutine ... def f(): ... with (yield lock.acquire()): ... # Do something holding the lock. ... pass ... ... # Now the lock is released.
Do you need to release the lock manually after the with or is that the purpose of using the with statement in that block? If this is the case why is there a separate release() and does this function need to be yielded?
原文:https://stackoverflow.com/questions/40083970
更新时间:2023-11-15 22:11