Modify object via Python multiprocessing.Pool: strange behavior -
I have an object with two characteristics: a dict and an int. When I modify the object using a forked process through multiprocessing. Poll, I take the object back with the modified int attribute, but the word is not modified. Why is it like this? Some Diff Forks () from Multiprocessing Import: For some classes () I in range (10): someObject.method (i) print ("In the fork, some object is Dct =% s and nbr =% i" % (SomeObject.dct, someObject.nbr)) Some object def test (): pool = pool (process = 1) result = pool.apple (func = fork) prints ("main, some objects in DCT =% s and NBR =% i "% (result.dct, result.nbr)) class some object (dct = {} nbr = 0 def method (self, nbr): self.dct [nbr] = nbr self.nbr + = Nbr if __name __ == '__ Main__ ': test ()
in output:
, fork, someObject in dct = {0: 0, 1: 1, 2: 2, 3: 3 In main, some objects in dct = {} and nbr = 45, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9} and NBR = 45
SomeClass.dct and SomeClass.nbt
From the hair process (es)
The Causes NBR has been updated but dct is that nbr actually becomes an example variable When you self.nbr + = nbr , which gets spicy and the original process is sent back but you have never specified anything at self.dct , Hence the self.dct (which in fact refers to SomeClass.dct ) does not get spicy.
You see this by defining some class (object) class