Guest User

Untitled

a guest
Jun 25th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. # Demo 1
  2. """
  3. The 'd' and 'i' arguments used when creating num and arr are typecodes of the kind used by the array module: 'd' indicates a double precision float and 'i' indicates a signed integer. These shared objects will be process and thread-safe.
  4.  
  5. For more flexibility in using shared memory one can use the multiprocessing.sharedctypes module which supports the creation of arbitrary ctypes objects allocated from shared memory.
  6. """
  7. from multiprocessing import Process, Value, Array
  8.  
  9. def f(n, a):
  10. n.value = 3.1415927
  11. for i in range(len(a)):
  12. a[i] = -a[i]
  13.  
  14. if __name__ == '__main__':
  15. num = Value('d', 0.0)
  16. arr = Array('i', range(10))
  17.  
  18. p = Process(target=f, args=(num, arr))
  19. p.start()
  20. p.join()
  21.  
  22. print(num.value)
  23. print(arr[:])
Add Comment
Please, Sign In to add comment