I am using pathos.multiprocessing to run a function in parallel processes and with different input arguments per process. Here is a minimum working example:
import pathos.multiprocessing as mp
from time import sleep
def my_func(x, y):
for i in range(x):
print(y+i)
sleep(.2)
return i + y
seq = [(100, 4), (100, 5)]
processes = 2
print ("Multiprocessing...")
pool = mp.Pool(processes)
resultsObj = pool.starmap_async(my_func, seq )
pool.close()
results = resultsObj.get()
As expected, the results are printed mixed up from the 2 processes, like so:
Multiprocessing...
4
5
5
6
7
6
7
8
8
9
10
9
10
11
Is there a way to drive the results to 2 different terminal to watch the progress? Or any other way to have the results printed in a "per process" fashion?
I'm the
pathosandmultiprocessauthor. One way to split the output is to compose a nested map. Essentially, if you have a function that pipes the input to a terminal, then use apathos.pools.ThreadPooltomapthe printing to two different terminals in thread parallel. As you are only working with two processes, then you could just include the function to split the output to the different terminals inside the mapped function you are using above. If you just want to know what process each output is coming from, you can alternately usemultiprocess.process.current_process()oros.getpid().