Daemonic processes in multiprocessing - solved

Pascal Chambon chambon.pascal at wanadoo.fr
Sat May 2 18:33:15 CEST 2009

Pascal Chambon a écrit :
> Hello everyone
> I've just read the doc of the (awesome) "multiprocessing" module, and 
> there are some little things I don't understand, concerning daemon 
> processes (see quotes below).
> When a python process exits, the page says it attempts to join all its 
> children. Is this just a design choice, or are there constraints 
> behind this ? Because normally, when a parent process exits, its child 
> gets adopted by init, and that can be useful for creating daemons, 
> can't it ?
> Concerning daemons processes, precisely, the manual states that they 
> are all terminated when their parent process exits. But isn't it 
> contrary to the concept of dameons, which are supposed to have become 
> independent from their parent ?
> And I don't understand how "the initial value (of the "daemonic" 
> attribute) is inherited from the creating process", since "daemonic 
> processes are not allowed to create child processes". Isn't it the 
> same to say that "daemonic" is always false by default, then ?
> And finally, why can't daemonic processes have children ? If these 
> children get "orphaned" when the daemonic process gets terminated (by 
> its parent), they'll simply get adpoted by init, won't they ?
> Thanks a lot for helping me get rid of my confusion,
> regards,
> Pascal
> =========QUOTES==========
> daemon¶ 
> <http://docs.python.org/library/multiprocessing.html#multiprocessing.Process.daemon>
>     The process's daemon flag, a Boolean value. This must be set
>     before start()
>     <http://docs.python.org/library/multiprocessing.html#multiprocessing.Process.start>
>     is called.
>     The initial value is inherited from the creating process.
>     When a process exits, it attempts to terminate all of its daemonic
>     child processes.
>     Note that a daemonic process is not allowed to create child
>     processes. Otherwise a daemonic process would leave its children
>     orphaned if it gets terminated when its parent process exits.
>     ----------------------
> Similarly, if the child process is non-daemonic then the parent
> process may hang on exit when it tries to join all its non-daemonic children.
> --------------
> Remember also that non-daemonic
> processes will be automatically be joined.
> ------------------------------------------------------------------------
> --
> http://mail.python.org/mailman/listinfo/python-list
Allright, I guess I hadn't understand much about "daemonic processes" in 
python's multiprocessing module.

So, for those interested, here is a clarification of the concepts, as 
far as I've understood - please poke me if I'm wrong somewhere.

Usually, in Unix, daemon processes are processes which got disconnected from
their parent process and from terminals, and work in the background, often under a
different user identity.
The python multiprocessing module has the concept of "daemon" too, but this
time in reference to the "threading" module, in which dameons are just
threads that wont prevent the application termination, even if they are
still running. Thus, daemonic processes launched through multiprocessing
API are normal processes that will be terminated (and not joined) if 
non-dameonic processes are all over.

Thus, not much in common between "traditionnal" *nix daemon processes, and python multiprocessing daemon processes.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090502/39494597/attachment.html>

More information about the Python-list mailing list