I am trying to implement multiprocessing in my program.
Initially, I wrote this code.
pool = mp.Pool(mp.cpu_count())
for i in range(0, 10000):
bid = i
ask = i
pool.apply_async(function1, args=(bid, ask,))
pool.apply_async(function2, args=(bid, ask,))
pool.apply_async(function3, args=(bid, ask,))
pool.close()
pool.join()
This gave me an error:
Python ValueError: Pool is still running
So I modified the code to:
for i in range(0, 10000):
bid = i
ask = i
pool = mp.Pool(mp.cpu_count())
pool.apply_async(function1, args=(bid, ask,))
pool.apply_async(function2, args=(bid, ask,))
pool.apply_async(function3, args=(bid, ask,))
pool.close()
pool.join()
This doesn't execute at all & shows a blank terminal.
What I'm trying to achieve is for every value in the range I want to run 3 functions in parallel, only after these 3 functions are executed, it should move to the next i
value in the range(0,1000)
.