Jonny
Jonny

Reputation: 61

Python3: Shared Array with strings between processes

I want to share a list with strings between processes, but unfortunately I receive the error message "ValueError: character U+169ea10 is not in 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 someone knows what I am doing wrong?

Regards Jonny

Upvotes: 4

Views: 879

Answers (1)

Brendan Abel
Brendan Abel

Reputation: 37509

Your ctype doesn't match the content of your Array. Your initializing data should be a list of strings to match the ctype you're specifying. You're initializing it with range(3), which evaluates to integers, not strings.

Should be more like

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

From the docs

c_wchar_p

Represents the C wchar_t * datatype, which must be a pointer to a zero-terminated wide character string. The constructor accepts an integer address, or a string.

Upvotes: 1

Related Questions