Hello friends,<br><br>I'm writing some Python app that makes use of the multiprocessing and Queue api to perform<br>transaction jobs.<br><br>My problem is that, the queue always report empty even though I can confirm that there are items in it.<br>

<br>Below is the code I'm working with:<br><br>import multiprocessing<br>from multiprocessing import Process, Queue<br>from Queue import Empty<br><br>def process(**kwargs):<br>    q = kwargs['q']<br>    # Don't start the process if there's no item in queue<br>

    if q.empty():<br>        print 'empty queue'<br>        multiprocessing.Process() # Process defaults to None<br>    else:<br>        p = multiprocessing.Process(target=transaction_queue, args=(kwargs))<br>        p.start()<br>

<br>def put_in_queue(items={}):    <br>    print items<br>    <br>    q = multiprocessing.Queue()<br>    <br>    try:<br>        for k,v in items.iteritems():<br>            data = v #data is a dict<br>            timeout = data.get(u'timeout')<br>

            <br>            # Put the transaction item in the queue at a specific timeout<br>            # period<br>            q.put(data, False, timeout)<br>            print "{0} put to queue".format(data)<br>

            transaction_queue(q, data, timeout, False)<br><br>    except (KeyError, AttributeError, ValueError):<br>        print 'Incorrect data format'<br><br>def transaction_queue(queue, item, timeout, block=False):<br>

    queue = multiprocessing.Queue()<br>    if item is not {} and timeout is not 0:<br>        print "Items are {0}".format(item)<br>        for i in range(len(item)):<br>            try:<br>                d = queue.get(block)<br>

                print d<br>            except Empty:<br>                print 'Fees queue empty at %s' % (i)<br>            else:<br>                return process(q=queue, i=d, t=timeout)<br>    else:<br>        print 'No item in the queue to get'<br>

<br>A JSON POST from CURL calls put_in_queue callback:<br><br> curl -v -H "Content-Type: application/json" -X POST --data 'fees={"fees":{"status":"pending","timeout":5}, "hostel":{"status":"pending","timeout": 3}}' <a href="http://127.0.0.1:8000/transaction/add/">http://127.0.0.1:8000/transaction/add/</a> > post_data.txt <br>

<br>At code run, the output is:<br><br>{u'status': u'pending', u'timeout': 3} put to queue<br>Items are {u'status': u'pending', u'timeout': 3}<br>Fees queue empty at 0<br>Fees queue empty at 1<br>

{u'status': u'pending', u'timeout': 5} put to queue<br>Items are {u'status': u'pending', u'timeout': 5}<br>Fees queue empty at 0<br>Fees queue empty at 1<br><br>Q: Why are my queues empty even though there are items in it?<br>

<br>Thanks you for the suggestions and answers.<br clear="all"><br>-- <br>Odeyemi 'Kayode O.<br><a href="http://www.sinati.com" target="_blank">http://www.sinati.com</a>. t: @charyorde<br><br>