I'm working on a problem that requires me to run X (10, 20 or 30) processes at once, at the same time. Is that possible? My understanding of computer architecture is weak, sorry about that.
I've looked into Python 3's multiprocessing module, but I couldn't get it to work as I intend. For example:
def test(number):
for i in range(4):
print("process {}, iteration {}".format(number, i))
pool = ThreadPool(4)
processes = [i for i in range(10)]
pool.map(test, processes)
Output is something like this:
process 0, iteration 0
process 0, iteration 1
process 0, iteration 2
process 0, iteration 3
process 1, iteration 0
process 1, iteration 1
process 1, iteration 2
process 1, iteration 3
...
What I'd want is:
process 0, iteration 0
process 1, iteration 0
process 2, iteration 0
process 3, iteration 0
process 4, iteration 0
...
process 9, iteration 0
process 0, iteration 1
...
It doesn't really matter to me the order that the iterations occur, just that all 10 processes start at the same time. Python's pool method seems to be start N processes, then waits for them to finish, then starts the next N processes, etc. I'd like to start all processes at once.
Is that possible? Thanks!