Usually i use following code, and it works fine when you do not matter in which order function process_func will handle some parameter:
params = [1,2,3,4,5 ... ]
def process_func():
...
pool = new Pool(40)
pool.map(process_func, params)
pool.close()
pool.join()
In example above we have processes of one type, with maximum simultanious number of 40. But.. imagine we have processes (parameters) of different type, which should be executed simultaniously. For example, in my selenium grid i have 40 firefox, 40 chromes. And i have 5000 test cases, some of them prefer chrome, some of them firefox, some of them does not matter.
For example, lets say we have following types:
- type firefox: maximum simultanious number: 40
- type chrome: maximum simultanious number: 40
In this case our pool will have maximum of 80 simultanious processes, but there is strict rule: 40 of them must be firefox, 40 of them must be chromes.
It means that params won't be taken one after each other. Pool must select value from params list in a way to have maximum of each process type.
How it is possible to achieve that?