I have this:
#!/usr/bin/env python
import multiprocessing
class MultiprocessingTest(object):
def __init__(self):
self.cmd = ''
def for_process_A(self):
self.cmd = "AA"
print "%s executing and cmd is %s" % (multiprocessing.current_process().name, self.cmd)
def for_process_B(self):
self.cmd = "BB"
print "%s executing and cmd is %s" % (multiprocessing.current_process().name, self.cmd)
if __name__ == '__main__':
obj = MultiprocessingTest()
process_A = multiprocessing.Process(target=obj.for_process_A, name='process_A')
process_B = multiprocessing.Process(target=obj.for_process_B, name='process_B')
process_A.start()
process_B.start()
process_A.join()
process_B.join()
Question:
Do the two processes share the variable cmd?
Do both processes have a separate class MultiprocessingTest definition and work off of that?
Independent copies of which data exists in the two processes?
I am trying to understand from a theoretical standpoint what is actually happening here. Can you please comment on that?
Test Run o/p:
$ ./commonvar.py
process_A executing and cmd is AA
process_B executing and cmd is BB
Process, the entire process is forked - i.e. memory is copied. That's putting it a little simplistically, but for the purposes of a mental exercise, all your objects split into two - one copy stays in the parent process, the other heads off to the new process.