Wednesday, July 13, 2022

shared memory in python multiprocessing

when running a multiprocessing sometimes there is a need to share some variable across processes

the simplest way is by using multiprocessing.Value or multiprocessing.Array

use multiprocessing.Value if the variable a simple numeric (int/double) variable, just replace 'i' (integer) into 'd' (double) as you need.

use 'c' in multiprocessing.Array if the the data is a string or a byte, for other types refer to ctypes or array module

No comments:

Post a Comment