I have a ctypes wrapper for a library. Unfortunately, this library is not 100% reliable (sometimes segfaults, etc.). Due to the way it is used, I want the shell to be sufficiently robust against a library crash.
The best way to do this seems to be to deploy the process and send the results from the child. I would like to do something in this direction:
r, w = os.pipe()
pid = os.fork()
if pid == 0:
result = ctypes_fn()
os.write(w, pickle.dumps(result))
os.close(w)
else:
os.waitpid(pid, 0)
result = os.read(r, 524288) # can be this big
os.close(r)
return pickle.loads(result)
This does not quite work. A broken process freezes during recording. Am I trying to send too much at once? Is there a simpler solution to this problem?
source
share