[英]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]". 我想在进程之间共享一个包含字符串的列表,但不幸的是我收到错误消息“ValueError:character U + 169ea10不在[U + 0000; U + 10ffff]范围内”。
Here is the Python 3 code: 这是Python 3代码:
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 关心强尼
Your ctype
doesn't match the content of your Array
. 您的ctype
与Array
的内容不匹配。 Your initializing data should be a list of strings to match the ctype
you're specifying. 您的初始化数据应该是一个字符串列表,以匹配您指定的ctype
。 You're initializing it with range(3)
, which evaluates to integers, not strings. 您正在使用range(3)
初始化它,它将计算为整数,而不是字符串。
Should be more like 应该更像
a = Array(c_wchar_p, ('', '', ''), lock=lock)
c_wchar_p c_wchar_p
Represents the C wchar_t * datatype, which must be a pointer to a zero-terminated wide character string. 表示C wchar_t *数据类型,该数据类型必须是指向以零结尾的宽字符串的指针。 The constructor accepts an integer address, or a string. 构造函数接受整数地址或字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.