-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Copying bytes object to shared memory list truncates trailing zeros #106939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
While that is "surprising" behavior, the implementation of that ShareableList does not appear to make good guarantees.
Workaround: unconditionally append a single non-0 character or byte to any shared data when putting items in and unconditionally ignore the final character (truncation or memoryview) on the consuming side. There are other constraints worth documenting as well. those "int"s are a maximum of 8 bytes struct packed without specifying if they are signed or not. https://docs.python.org/3/library/multiprocessing.shared_memory.html#multiprocessing.shared_memory.ShareableList needs improvement. |
FWIW, the workaround you proposed is what I ended up doing in my code to get around this. |
…7266) * pythongh-106939: document ShareableList nul-strip quirk. * Mention the `int` size constraint. (cherry picked from commit 70dc009) Co-authored-by: Gregory P. Smith <[email protected]>
…7266) * pythongh-106939: document ShareableList nul-strip quirk. * Mention the `int` size constraint. (cherry picked from commit 70dc009) Co-authored-by: Gregory P. Smith <[email protected]>
* pythongh-106939: document ShareableList nul-strip quirk. * Mention the `int` size constraint.
I'm willing to work on a fix for this. Is implementing the workaround mentioned into To me, it seems like the issue is that we're padding all |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
tl;dr; See stack overflow post
When copying a
bytes
object to a shareable list, the trailing zeros are stripped causing data loss. This doesn't appear in the documentation as far as I can tell, and seems to be unexpected behavior related to the implementation.Example code:
Output:
Offending portion of CPython code:
Linked PRs
The text was updated successfully, but these errors were encountered: