So i have something similar to this
import multiprocessing
class MyFancyClass(object):
def __init__(self, name):
self.name = name
def do_something(self):
proc_name = multiprocessing.current_process().name
print 'Doing something fancy in %s for %s!' % (proc_name, self.name)
def worker(q):
obj = q.get()
obj.do_something()
if __name__ == '__main__':
urls = [
'http://www.python.org',
'http://www.python.org/about/',
'http://www.python.org/community/awards/'
# etc..
]
queue = multiprocessing.Queue()
p = multiprocessing.Process(target=worker, args=(queue,))
p.start()
queue.put(MyFancyClass('Fancy Dan'))
# Wait for the worker to finish
queue.close()
queue.join_thread()
p.join()
What i want to do is have 4 or more "workers" start and process the urls and when one finishes start another one. What would be the best way to do this. I spend two days on this and can't figure it out.
Thank you Thank you.