# test _thread lock object using a single thread## MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltdimport _thread# create locklock = _thread.allocate_lock()print(type(lock) == _thread.LockType)# should be unlockedprint(lock.locked())# basic acquire and releaseprint(lock.acquire())print(lock.locked())lock.release()print(lock.locked())# try acquire twice (second should fail)print(lock.acquire())print(lock.locked())print(lock.acquire(0))print(lock.locked())lock.release()print(lock.locked())# test with capabilities of lockwith lock:print(lock.locked())# test that lock is unlocked if an error is rasiedtry:with lock:print(lock.locked())raise KeyErrorexcept KeyError:print('KeyError')print(lock.locked())# test that we can't release an unlocked locktry:lock.release()except RuntimeError:print('RuntimeError')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。