python - Accessing elements of a sharedctypes Array -
i trying save memory sharing memory between processes using sharedctypes part of multiprocessing module.
the example given in documentation requires values of c array recovered, in example put in list, before being used:
from multiprocessing import process, lock multiprocessing.sharedctypes import value, array ctypes import structure, c_double class point(structure): _fields_ = [('x', c_double), ('y', c_double)] def modify(n, x, s, a): n.value **= 2 x.value **= 2 s.value = s.value.upper() in a: a.x **= 2 a.y **= 2 if __name__ == '__main__': lock = lock() n = value('i', 7) x = value(c_double, 1.0/3.0, lock=false) s = array('c', b'hello world', lock=lock) = array(point, [(1.875,-6.25), (-5.75,2.0), (2.375,9.5)], lock=lock) p = process(target=modify, args=(n, x, s, a)) p.start() p.join() print(n.value) print(x.value) print(s.value) print([(a.x, a.y) in a]) <---- line surely negates memory saved sharing between processes because shared information copied if each process had loaded information individually. please correct me if miss understanding way working (which am).
my question: can information in sharedctypes array a accessed directly?
i had imagined this:
print(a[:]) <-- prints values instead of:
print([a in a]) <-- creates new list of values in a, prints
Comments
Post a Comment