2

When sharing a rawarray between different processes using multiprocessing, is it a problem to have all the children write / modify the raw array?

Does one need to handle lockings etc in such a case?

1 Answer 1

2

From python documentation:

multiprocessing.sharedctypes.RawArray(typecode_or_type, size_or_initializer)

Return a ctypes array allocated from shared memory.

typecode_or_type determines the type of the elements of the returned

array: it is either a ctypes type or a one character typecode of the kind used by the array module. If size_or_initializer is an integer then it determines the length of the array, and the array will be initially zeroed. Otherwise size_or_initializer is a sequence which is used to initialize the array and whose length determines the length of the array.

Note that setting and getting an element is potentially non-atomic;

use Array() instead to make sure that access is automatically synchronized using a lock.

So, you may need to use multiprocessing.sharedctypes.Array which allows locking and synchronization between processes.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I do care about atomicity. Is it possible to define a multi-dimensional array using multiprocessing.sharedctypes.Array?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.