Guest User

Untitled

a guest
Jun 22nd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. r, w = os.pipe()
  2. pid = os.fork()
  3.  
  4. if pid == 0:
  5. # child
  6. result = ctypes_fn()
  7. os.write(w, pickle.dumps(result))
  8. os.close(w)
  9. else:
  10. # parent
  11. os.waitpid(pid, 0)
  12. result = os.read(r, 524288) # can be this big
  13. os.close(r)
  14.  
  15. return pickle.loads(result)
  16.  
  17. #parent
  18. while waitpid(pid, WNOHANG) == (0, 0):
  19. result = os.read(r, 1024)
  20. #sleep for a short time
  21. #at this point the child process has ended
  22. #and you need the last bit of data from the pipe
  23. result = os.read(r, 1024)
  24. os.close(r)
Add Comment
Please, Sign In to add comment