- Where Developers Learn, Share, & Build Careers
I found the following example on this site somewhere:
import multi import ctypes import numpy NP shared_array_base = multiprocessing.Array (ctypes.c_double, built 10 * 10) shared_array = np.ctypeslib.as_array (shared_array_base.get_obj ()) shared_array = shared_array.reshape (10, 10) as # not copy loud shared_array.base Was there. Based shared_array_base.get_obj () # parallel processing def My_func (I, Def_param = Shared_array): Shared_array [i] = i if __name__ == '__main__': pool = multiprocessing.Pool (procedures = 4) pool.map ( my_func, (10)) print shared_array the above code works fine, but I want to add an array of shared array, some (like shared_array + = some_other_array up instead shared_array [i]; = i)
local variable 'shared_array' assignments referenced earlier
there is no reason to consider that I ACE Can not?
is that a variable is assigned anywhere in a function, it is regarded as a local variable Is shared_array + = some_other_array equals shared_array = shared_array + some_other_array . Thus shared_array is considered as a local variable, which is not present at the time when you try to use it on the right side of the assignment. If you want to use the global shared_array variable, you must explicitly mark it by entering a global share_re in your function. The error with which you do not see shared_array [i,:] = i is that it does not specify the variable shared_array . Instead, it changes the object that tells a piece of it. In Python, a bare name (for example, shared_array = ... ) is different from another type of assignment (for example, shared_array [...] = ... ), although they look similar. Note, incidentally, there is nothing with multi-generator of error.
Comments
Post a Comment