通过RLOCK方式,解决多线程之间修改共享对象不出问题,使线程的资源独占
import threading import time lock=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()
时间: 2024-10-16 11:52:01