why the method get() of python Queue is hang on there?

skip at pobox.com skip at pobox.com
Mon Aug 14 11:25:17 EDT 2006


    zxo> import Queue
    zxo> b = Queue.Queue(0)
    zxo> b.put(9999)
    zxo> b.get()   # this is ok, it pops out 9999
    zxo> b.get()   # this one does not return anything and is hang on there

    zxo> Anybody knows what is going on with the second b.get()?

Queue objects are meant to be used in a multithreaded application.  By
default, when the Queue is empty, a consumer calling get() will block until
a producer put()s something else into it.  From the documentation:

    get([block[, timeout]])
        Remove and return an item from the queue. If optional args block is
        true and timeout is None (the default), block if necessary until an
        item is available....

Skip



More information about the Python-list mailing list