• Queue


    import Queue
    q = Queue.Queue(2)
    print q.empty()
    q.put('eeee')
    q.put('bb')
    print q.qsize()  #返回值为2
    q.get() #get一个,则Queue中会空出来一个位置
    print q.qsize()  #返回值为1

     print q.queue #查看当前队列中的内容

     q.queue.clear()  #清空当前队列

    import Queue
    q = Queue.Queue(2)
    print q.empty()
    for i in range(1,4):
        try:
            q.put_nowait(i)    #使用put_nowait()将数据放入Queue,如果队列满则抛出Full error。如果直接使用q.put()则当Queue满时,会产生死锁。取数据则使用print q.get_nowait(),同put_nowait()
        except:
            print ‘q is full’
    print q.qsize()
    while not q.empty():
        print q.get_nowait()  #取值:先进先出
    import Queue
    q = Queue.Queue(20)
    for i in range(1,8):
        try:
            q.put_nowait(i)    
        except:
            print 'q is full'
    q.queue.reverse()   #倒序取值:先进后出
    while not q.empty():
        print q.get_nowait()
    Queue的常用方法:
       Queue.qsize() #返回队列的大小 
       Queue.empty() #如果队列为空,返回True,反之False 
       Queue.full()  #如果队列满了,返回True,反之False
       Queue.full 与 maxsize 大小对应 
       Queue.get([block[, timeout]]) #获取队列,timeout等待时间,调用队列对象的get()方法从队头删除并返回一个项目。可选参数为block,默认为True。如果队列为空且block为True,get()就使调用线程暂停,直至有项目可用。如果队列为空且block为False,队列将引发Empty异常。 
       Queue.get_nowait() #相当Queue.get(False)
       Queue.put(item)    #非阻塞写入队列,timeout等待时间,调用队列对象的put()方法在队尾插入一个项目。
       put()有两个参数,第一个item为必需的,为插入项目的值;第二个block为可选参数,默认为1。如果队列当前为空且block为1,put()方法就使调用线程暂停,直到空出一个数据单元。如果block为0,put方法将引发Full异常。
       Queue.put_nowait(item) #相当Queue.put(item, False)
       Queue.task_done()   #在完成一项工作之后,Queue.task_done() 函数向任务已经完成的队列发送一个信号Queue.join() 实际上意味着等到队列为空,再执行别的操作.
  • 相关阅读:
    http://blog.csdn.net/sinat_33950284/article/details/50646622
    http://edu.csdn.net/course/detail/2798?ref=blog&loc=0
    微服务架构的分布式事务解决方案
    http://www.cnblogs.com/chenpi/p/5999707.html
    http://blog.csdn.net/hejingyuan6/article/details/47403299
    https://www.oschina.net/p/goshop2
    https://github.com/SuperMan42/MVP
    spring mvc
    http://www.iyaxi.com/2015-11-17/732.html
    场景测试
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/5286449.html
Copyright © 2020-2023  润新知