Python3: shared array with strings between processes

I want to share a list with strings between processes, but unfortunately I get the error message "ValueError: character U + 169ea10 is not in the range [U + 0000; U + 10ffff]".

Here is the Python 3 code:

from multiprocessing import Process, Array, Lock
from ctypes import c_wchar_p
import time

def run_child(a):
    time.sleep(2)
    print(a[0]) # print foo
    print(a[1]) # print bar
    print(a[2]) # print baz
    print("SET foofoo barbar bazbaz")
    a[0] = "foofoo"
    a[1] = "barbar"
    a[2] = "bazbaz"

lock = Lock()
a = Array(c_wchar_p, range(3), lock=lock)
p = Process(target=run_child, args=(a,))
p.start()

print("SET foo bar baz")
a[0] = "foo"
a[1] = "bar"
a[2] = "baz"

time.sleep(4)

print(a[0]) # print foofoo
print(a[1]) # print barbar
print(a[2]) # print bazbaz

Does anyone know what I'm doing wrong?

Jonny Relationship

+4
source share
1 answer

Yours ctypedoes not match your content Array. Your initialization data should be a list of strings that will match the specified ctype. You initialize it with a help range(3)that calculates integers, not strings.

Should be more like

a = Array(c_wchar_p, ('', '', ''), lock=lock)

From docs

c_wchar_p

C wchar_t *, . .

+1

Source: https://habr.com/ru/post/1627517/


All Articles