Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ctype_multiprocessing.py
- from multiprocessing import Process, Lock
- from multiprocessing.sharedctypes import Value, Array
- from ctypes import Structure, c_double
- class Point(Structure):
- _fields_ = [('x', c_double), ('y', c_double)]
- def modify(n, d, s, A):
- n.value **= 2
- d.value **= 2
- s.value = s.value.upper()
- for a in A:
- a.x *= 3
- a.y *= 3
- if __name__ == '__main__':
- lock = Lock()
- n = Value('i', 7)
- d = Value(c_double, 1.0/3.0, lock=False)
- s = Array('c', b'hello world', lock=lock)
- A = Array(Point, [(1.875,-6.25), (-5.75,2.0), (2.375,9.5)], lock=lock)
- print(n.value)
- print(d.value)
- print(s.value)
- print([(a.x, a.y) for a in A])
- print
- p = Process(target=modify, args=(n, d, s, A))
- p.start()
- p.join()
- print(n.value)
- print(d.value)
- print(s.value)
- print([(a.x, a.y) for a in A])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement