Recently in a project, I had a multiprocessing Process that crashed. A child process was supposed to do a calculation, then send it to the parent process in a Pipe. If the child crashed, the parent would freeze while reading from the pipe. Is there a ‘correct’ way to send data that would avoid blocking the parent forever if a child dies?
This is an example that reproduces the problem I’m having:
import multiprocessing as mp
def f(pipe):
a = 1/0
pipe.send('hola')
parent, child = mp.Pipe()
proc = mp.Process(target=f, args=(child,))
proc.start()
print "Grabbing result"
print "Result: {0}".format(parent.recv())
proc.join()
The parent process could use the connection’s
poll(...)method to determine if any result was forthcoming with a reasonable time limit:When I run this code I get the following results: