Lets say I have 10000 tasks at hand. How can I process them in parallel, running precisely 8 processes at any time? The moment a task is finished, the next task should be fetched for execution immediately.
for e in arr:
pr=Process(target=execute, args=(q,e))
pr.start()
pr.join()
I want to do this because my CPU has only 8 hardware threads. Swarming it with 10000 tasks at once will slow down the overall computation due to the switching overhead. My memory is also limited.
(Edit: This is not a duplicate of this question as I am not asking how to fork a process.)