Implement multiprocessing without inheriting parent file handle

Mark H Harris harrismh777 at gmail.com
Fri Mar 21 13:25:36 EDT 2014


On 3/21/14 10:28 AM, Antony Joseph wrote:
> How can i implement multiprocessing without inherit file descriptors
> from my parent process?

I'll bite...

If what you mean by 'multiprocessing' is forking a process, to get a 
child process, which will then do some parallel processing for some 
reason, the answer is two-fold: 1) you can't, and 2) you might try using 
threads.  (there are other answers too)

When you fork a process the only differences between the child and the 
parent is 1) process number, and 2) one is the 'parent' and one is the 
'child'.  They are 'exact' copies of one another.

In socket daemons the parent always listens on a given port, then forks 
a child process to establish a secondary port(s) to handle the comm 
link;  at that point (instant) both the parent and the child ask a 
simple question, "Am I the parent?"  If so, the code goes back to 
listening... if not, the code (the child) establishes the necessary comm 
ports and handles the server request.  When finished the child notifies 
the parent and ends.

You can try parent/child arrangements (maybe use rpc, or shared memory 
segments for inter process comm), or you might try threads... which are 
a separate unit of execution (not a full process copy) but with access 
to the parent's memory.

Otherwise, you might want to tell the list some of the background of 
your difficulty, or put the difficulty in pythonic terms, or simply ask 
your python related question with as much simplified but complete detail 
as possible.

Is there a python question in there someplace?

marcus



More information about the Python-list mailing list