Hello.

I have a strange problem while using the Queue class of Gevent in a Django view.

Basically I have a Django web application running on uWSGI with the Gevent loop 
engine. One of the views creates a bounded Queue and spawns a Greenlet that 
obtains objects from this queue and processes them, while the main loop inserts 
objects in the queue at a certain rate.

If the producer manages to keep ahead of the consumer, everything works fine, 
but as soon as the consumer executes Queue.get(timeout=60.0) on an empty Queue, 
it raises the Empty exception immediately.

Stepping through the code I see that it enters here:

queue.py:
       elif self.hub is getcurrent():
           # special case to make get_nowait() runnable in the mainloop greenlet
           # there are no items in the queue; try to fix the situation by 
unlocking putters
           while self.putters:
               self.putters.pop().put_and_switch()
               if self.qsize():
                   return self._get()
           raise Empty

While debugging I found that the Greenlet that I spawn has the following ID: 
<Greenlet at 0x108078730: 
obtain_blocks_swift(UUID('4501548b-bd40-406b-8da5-d778e4a04e17'), <bound method 
Feeder.read of <api.content.Feeder o)>

But after I execute the first Queue.get(), when the execution flow returns, I'm 
running on the HUB context: <Hub at 0x106ceb690 select default pending=0 ref=7 
resolver=<gevent.resolver_thread.Resolver at 0x106ce4a10 pool=<ThreadPool at 
0x106d44a90 0/2/10>> threadpool=<ThreadPool at 0x106d44a90 0/2/10>>

In this context, when I get to execute Queue.get(60) and the Queue is empty, 
the timeout is not honored and an Empty exception is raised. It seems to me 
that the execution context should not change to the HUB, but I'm not sure if 
this is a Gevent bug or a uWSGI bug in the Gevent loop engine...

I'm running uWSGI 2456:6837d6bfd864 and Gevent 1.0b3.

Does anybody know where the problem lies?

Thanks,
André
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to