通过RLOCK方式,解决多线程之间修改共享对象不出问题,使线程的资源独占
import threadingimport timelock=threading.Rlock()def run(name): lock.acquire() print "i am mult-threding",i lock.release() time.sleep(2)for i in range(20): t=threading.Thread(target=run,args=(i,)) t.start()
本文共 305 字,大约阅读时间需要 1 分钟。
通过RLOCK方式,解决多线程之间修改共享对象不出问题,使线程的资源独占
import threadingimport timelock=threading.Rlock()def run(name): lock.acquire() print "i am mult-threding",i lock.release() time.sleep(2)for i in range(20): t=threading.Thread(target=run,args=(i,)) t.start()
转载于:https://blog.51cto.com/dbaspace/1870899