You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Value error for string shared memory in multiprocessing #76472
pre_thread: a; aa
thread: a; aa
thread: b; bb
post_thread: b; bb
process: b; bb
process: c; cc
post_process: c; Traceback (most recent call last):
File "test2.py", line 30, in <module>
print(share_s.value) # <--- Blows here
File "<string>", line 5, in getvalue
ValueError: character U+ff92f210 is not in range [U+0000; U+10ffff]
It also raises ValueError.When use c_double or c_int, it works well.
Test in python3.7 and 3.8
hongweipeng commented on Sep 30, 2018
hongweipengmannequin
Mannequin
More actions
I think I know the reason. c_wchar_p corresponds to the string pointer wchar_t *.It's not a good idea to pass pointers between processes. As quoted from multiprocessing docs:
Note Although it is possible to store a pointer in shared memory remember that this will refer to a location in the address space of a specific process. However, the pointer is quite likely to be invalid in the context of a second process and trying to dereference the pointer from the second process may cause a crash.
Activity
magu commentedon Dec 12, 2017
It seems like sharing a string over processes is not possible.
produces:
Where the character value in the error message is different every time. To me this seems like a bug as it is working properly with threads as well as single characters. (Maybe relevant question also here: https://stackoverflow.com/questions/47763878/how-to-share-string-between-processes?noredirect=1#comment82492062_47763878)
For the case it matters:
Python 3.6.1 (Anaconda 4.4.0) on RHEL 6
hongweipeng commentedon Sep 29, 2018
This problem seems to be support for str.
It also raises ValueError.When use c_double or c_int, it works well.
Test in python3.7 and 3.8
hongweipeng commentedon Sep 30, 2018
I think I know the reason.
c_wchar_pcorresponds to the string pointerwchar_t *.It's not a good idea to pass pointers between processes. As quoted frommultiprocessingdocs:Note Although it is possible to store a pointer in shared memory remember that this will refer to a location in the address space of a specific process. However, the pointer is quite likely to be invalid in the context of a second process and trying to dereference the pointer from the second process may cause a crash.
https://docs.python.org/3.6/library/multiprocessing.html?#module-multiprocessing.sharedctypes
iritkatriel commentedon Oct 17, 2021
Is there anything left to do here?
It seems hongweipeng's explanation and the link to the documentation pretty much cover it.