multiprocessing: Correct usage of pool & queue?

A

Allen Fowler

Hello,

I have a list of tasks/items that I want handed off to
threads/processes to complete. (I would like to stick with process if
I could, since there is some CPU work here. )

Each task involves some calculations and a call to a remote server over urllib2/HTTP.

The
time to complete each task varies from 1 to 20 seconds depending on a
number of factors including variable delay on the remote server.

I would like to:

1) Have a maximum of 20 "in-flight" tasks. (thus worker processes?)

2)
Not overload the external server that each task is calling. No more
than "3 new tasks" per second. More "waiting" tasks may be OK, i need
to test it.

3) Certain tasks in my list must be processed in
the correct order. (I guess the asignment logic must somehow tag those
to by done by the same worker?)


Do any of you have suggestions? Can someone point me in the direction of sample code for this?

Thank you,
:)
 
A

Aahz

1) Have a maximum of 20 "in-flight" tasks. (thus worker processes?)

Good bet.
3) Certain tasks in my list must be processed in the correct order. (I
guess the asignment logic must somehow tag those to by done by the same
worker?)

The simpler way to do this would be to bundle these tasks into a single
queue object that contains a list of tasks. Each worker iterates over
the list of tasks that it receives, which could be a single task.
--
Aahz ([email protected]) <*> http://www.pythoncraft.com/

"To me vi is Zen. To use vi is to practice zen. Every command is a
koan. Profound to the user, unintelligible to the uninitiated. You
discover truth everytime you use it." (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top