Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- r, w = os.pipe()
- pid = os.fork()
- if pid == 0:
- # child
- result = ctypes_fn()
- os.write(w, pickle.dumps(result))
- os.close(w)
- else:
- # parent
- os.waitpid(pid, 0)
- result = os.read(r, 524288) # can be this big
- os.close(r)
- return pickle.loads(result)
- #parent
- while waitpid(pid, WNOHANG) == (0, 0):
- result = os.read(r, 1024)
- #sleep for a short time
- #at this point the child process has ended
- #and you need the last bit of data from the pipe
- result = os.read(r, 1024)
- os.close(r)
Add Comment
Please, Sign In to add comment