I'm trying to use a shared string variable between my Python processes, but it seems that I'm doing something wrong since I'm getting coredumps and invalid memory values.
I use multiprocessing.Value
to create a ctypes.c_char_p
value and use the value
attribute to access it. In my understanding of the Python docs the value attribute should be synchronized, as long it is an instance of Value
(contrary of an instance of RawValue
). Is that correct so far?
I've created a short example to demonstrate my use of Value
and to show the inconsistency while executing:
from multiprocessing import Process, Value
from ctypes import c_char_p
def process(v):
while True:
val = v.value
print val
while val == v.value:
pass
v = Value(c_char_p, None)
p = Process(target=process, args=(v,))
p.start()
for i in range(1,999):
v.value = str(i)
p.terminate()
c_char_p
is actually a pointer. – Prehensible