I'm currently writing a program that utilizes the multiprocessing tool in Python.
When I try to return the result from the function that utilizes multiprocessing, and then print it, it will first attempt to print it and prints None
. However, once it runs through the multiprocessing function and process, it will print again with the valid answers. This is odd, and I have figured out a way around it, but I'm curious as to if someone has a solid answer to why this happens.
Below is the function I use for multiprocessing.
def ParallelProc:
if __name__ == '__main__':
core = 7
p = mp.Pool(core)
solutions = p.map(calc, NEW_IC)
return solutions
Then I try to run it and set it to a variable, and print it like below
sol = ParallelProc()
print sol
My only guess is that it runs the multiprocessing in the background and moves the code forward, trying to print with nothing returned yet. Then once ParallelProc
converges, it starts again from that point.
This is an easy work around seen below
sol = ParallelProc()
if sol != None:
print sol
Any ideas as to what is going on?
FYI I'm running this code through the windows command prompt.