The way I understand it, another Python instance is kicked off with multiprocessing. If so,
a. Is a Python instance started for each multiprocessing process?
b. If one process is working on say, an in-memory database table and another process is working on another in-memory database table, how does Python manage the memory allocation for the 2 processes?
c. Wrt b), is the memory allocation persistant between invocations ie. if the first process is used continuously but the 2nd process is used infrequently, is the in-memory table re-created between process calls to it?
-
1. What do you mean by memory table? 2. Is your question only specific to a certain operating system or targeting the inside of a python process?User– User2014年01月24日 12:19:01 +00:00Commented Jan 24, 2014 at 12:19
-
the data structure is an "in-memory database table", could be a list or dictionary. question is not specific to a particular operating system.Henry Thornton– Henry Thornton2014年01月24日 12:26:25 +00:00Commented Jan 24, 2014 at 12:26
1 Answer 1
(a) yes
(b) Python pretty much doesn't manage it, the OS does
(c) Yes, if the second process exits then its resources are freed, regardless of the persistence of the first process. You can in principle use shared objects to allow the second process to use something that the first process arranges will persist. How that plays with the specific example of the "something" being a database table is another matter.
Running extra Python processes with multiprocessing is a lot like running extra Python (or for that matter Java) processes with subprocess. The difference is that multiprocessing gives you a suite of ways to communicate between the processes. It doesn't change the basic lifecycle and resource-handling of processes by the OS.
4 Comments
multiprocessing.Array as the type of the shared object. Or if process #2 doesn't modify list #2, just computes a result from it and returns that, then you don't need shared memory at all on a proper operating system -- you can fork instead and the OS will magically arrange that memory neither process modifies is never copied. Unfortunately Windows is not a proper OS. I define "proper" to mean "provides fork" ;-)Explore related questions
See similar questions with these tags.