I don't get python multiprocessing module. I start a process with the function and pass and object as its parameter. As I understand it, it should be the exact copy of that object. But if I try to print the address of that object it is the same in every process. How it is possible? Shouldn't address be different in every process? And if it is the same object in every process how come that changes to it are not global but local for every process?
I have my object defined like this:
class MyClass():
my_field = None
def __init__():
self.my_field = 0
And function which runs in separate process
def function_to_run_in_process(some_object):
print some_object
The result for multiple processes is something like:
<__main__.MyClass instance at 0x7f276419e5f0>
<__main__.MyClass instance at 0x7f276419e5f0>
<__main__.MyClass instance at 0x7f276419e5f0>
and so on.
If I tried to change some field of the object inside the process like this:
def function_to_run_in_process(some_object, process_lock):
process_lock.acquire()
some_object.some_field = some_object.some_field + 1
process_lock.acquire()
print some_object, 'with some_field = ', some_object.some_field, 'at address: ', hex(id(some_object.some_field))
I get the result similar to this:
<__main__.MyClass instance at 0x7f276419e5f0> with some_field = 1 at address 0xc5c428>
<__main__.MyClass instance at 0x7f276419e5f0> with some_field = 1 at address 0xc5c428>
<__main__.MyClass instance at 0x7f276419e5f0> with some_field = 1 at address 0xc5c428>
So, if the passed object is just a copy, why there are same addresses not only for the object, but even for its field? And if they are the same why the change to the field is not visible ?