1. What does it mean to "organize a program"?
This means that your program should work autonomously without any external resources. File sharing will give you problems with locking, memory sharing will either do the same, or it may lead to corruption due to several processes that modify data at the same time.
Here is an example of what would be a bad idea:
while some_queue_is_not_empty(): run_external_process(some_queue) def external_process(queue): item = queue.pop()
Versus:
while some_queue_is_not_empty(): item = queue.pop() run_external_process(item) def external_process(item):
This way you can avoid blocking problems with the queue and / or corruption due to the fact that several processes receive the same element.
2. How can I share resources by inheriting?
On Windows you cannot. On Linux, you can use file descriptors opened by parents; on Windows, this will be a completely new process, so you have nothing from your parent except what was given.
Example copied from: http://rhodesmill.org/brandon/2010/python-multiprocessing-linux-windows/
from multiprocessing import Process f = None def child(): print f if __name__ == '__main__': f = open('mp.py', 'r') p = Process(target=child) p.start() p.join()
On Linux, you will get something like:
$ python mp.py <open file 'mp.py', mode 'r' at 0xb7734ac8>
On Windows, you will get:
C:\Users\brandon\dev>python mp.py None
Wolph source share