- def f3():
- lock=DeferredLock()
- print 'start lock'
- def debug(lock,i):
- println(i)
- reactor.callLater(1,lock.release)
- def debug2(lock,i):
- println(i)
- lock.release()
- lock.acquire().addCallback(debug,1)
- lock.acquire().addCallback(debug,2)
- #twisted 队列 和 锁的测试用例
- def f4():
- q= DeferredQueue()
- q.put(1)
- q.get().addCallback(println)
- q.get().addCallback(println)
- reactor.callLater(2,q.put,3)
- reactor.callLater(2,q.put,3)
- reactor.callLater(2,q.put,3)
- def t():
- q.get().addCallback(println)
- reactor.callLater(4,t)
转载于:https://blog.51cto.com/shendongming/625626