I have some code that does the following:
- Creates a process (process is solvePuzzle(filename))
- Runs the process
- If the process finishes within timeLimit, do something
- If the process times out, do something else
My issue is with the third task; I want to be able to get the return value of the function that was processed. Here is my code (I made up the statement p.returnValue() as this is what I'm trying to do):
#Start process
p = multiprocessing.Process(target=globals()['solvePuzzle'], args=(filename,))
p.start()
#Wait for timeLimit seconds or until process finishes
p.join(timeLimit)
#If thread is still active
if p.is_alive():
print "Puzzle timed out after " + str(timeLimit) + " seconds!"
# Terminate
p.terminate()
p.join()
else:
print "Solution = " + str(p.returnValue())