Get multiprocessing.Queue to do priorities

Scott David Daniels Scott.Daniels at Acm.Org
Sat May 9 16:00:36 EDT 2009


uuid wrote:
> Scott David Daniels <Scott.Daniels at Acm.Org> wrote:
>> ? "one producer, many consumers" ?
>> What would the priority queue do?  Choose a consumer?
> 
> Sorry, I should have provided a little more detail. There is one
> producer thread, reading urls from multiple files and external input.
> These urls have a certain priority, and are fed to multiple consumer
> threads for fetching and further processing (XML parsing and such CPU
> intensive stuff). Since the content of the urls is changing over time,
> it is crucial to have a certain amount of control over the order in
> which the requests occur. So, to answer the question: 
> The priority queue would make sure that out of a number of
> asynchronously added items, those with a high priority are fetched first
> by the worker threads. Sounds like a perfect case for a heap, if only I
> could :)

2.6 has a PriorityQueue in the Queue module.
If you aren't using 2.6, you could copy the code for your own version.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list