In multiprocessing.Pool I am trying to show my prints in the the same order.
from multiprocessing import Pool
import time
def func(arg):
time.sleep(0.001)
print(arg, end=" ")
proc_pool = Pool(4)
proc_pool.map(func, range(30))
The output is: 0 1 8 9 10 11 14 15 6 7 16 17 4 5 12 13 18 19 2 3
or similar. It is not in the order 0 1 2 3 ...
I know that imap
can give better ordering ... but it's still not exactly what I want. I could override the print function to save it into a variable and print them all at once - but I would prefer showing them as soon as they complete - not when all complete.