Please ignore the below mail. I overlooked the fact that get function for Q is a blocking call.
Thanks, Amish On Thu, May 19, 2016 at 3:16 PM, Amish Anand <amishatiit...@gmail.com> wrote: > Hi > I am writing an application which basically solves a simple producer > consumer problem. Both producer and consumer run on separate threads. The > producer function writes to a Queue and continues producing data, whereas > the consumer thread function waits for items to be enqueued and once > present, it pops them out for processing. In the current implementation I > am waiting on an infinite while loop because if I don't then the thread > function will exit after processing one item in the queue and that is not > desired. Due to this infinite loop, thread function is hogging lot of CPU > (as a workaround I have added a sleep of 1sec to reduce the CPU usage), > however I feel there should be a proper mechanism to gracefully wait for > the items to be enqueued and then continuously wait for the items to be > added to the queue without exiting. I will try to experiment with threading > module event (set and wait) but that will be a tricky implementation I > believe. Appreciate your thoughts on this issue. > > Stub code of the thread handler on the consumer side: > > while True: > print '%s: Looking for the next enclosure' % i > url = q.get() > print '%s: Downloading:' % i, url > q.task_done() > time.sleep(1) > > Thanks, > Amish > > _______________________________________________ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers