Skip to content
Advertisement

python multiprocessing.Array typing

When creating an array, I want to put it inside a dataclass, but I cannot find the type of the returned object.

arr = multiprocessing.RawArray("i", 2)

If I do:

JavaScript

but multiprocessing.sharedctypes.c_long_Array_2 does not exists.
How can I use type hints, e.g arr: the_type with multiprocessing Array?

UPDATE
Pycharm example when using typing ctypes.c_long * 2, there’s still a value attribute which is invalid.

enter image description here

Advertisement

Answer

The shared array’s type is derived from the ctypes module. You could also perhaps use this module to help you be more explicit about the data type of the array:

JavaScript

Note: ctypes does not come with all the possibilities of array sizes so notice the ctypes.c_long * 2 syntax to indicate that it is an array of long of size = 2.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement