The answer may be right in front of me at the link below, but I still do not understand. I'm sure that after someone explains this to me, Darwin will call me.
An example from this link is here , although I made some changes to try to experiment and help my understanding.
Here is the code:
import multiprocessing import time import sys def daemon(): p = multiprocessing.current_process() print 'Starting: ', p.name, p.pid sys.stdout.flush() time.sleep(2) print 'Exiting: ', p.name, p.pid sys.stdout.flush() def non_daemon(): p = multiprocessing.current_process() print 'Starting: ', p.name, p.pid sys.stdout.flush() time.sleep(6) print 'Exiting: ', p.name, p.pid sys.stdout.flush() if __name__ == '__main__': d = multiprocessing.Process(name='daemon', target=daemon) d.daemon = True n = multiprocessing.Process(name='non-daemon', target=non_daemon) n.daemon = False d.start() time.sleep(1) n.start()
And the code output:
Starting: daemon 6173 Starting: non-daemon 6174 Exiting: non-daemon 6174
If the connection () is uncommented at the end, then the output:
Starting: daemon 6247 Starting: non-daemon 6248 Exiting: daemon 6247 Exiting: non-daemon 6248
I'm confused. b / c sleep demon is 2 seconds and non-demon is 6 seconds. Why doesn't he print the "Exit" message in the first case? The demon had to wake up in front of a non-demon and type a message.
The explanation from the site is as follows:
The output does not include the message βExitβ from the process daemon, since all non-demon processes (including the main program) before the daemon process wakes up from 2 seconds sleep.
but I changed it so that the demon had to wake up before the non-demon. What am I missing here? Thanks in advance for your help.
EDIT: Forgot to mention that I am using python 2.7, but apparently this problem is also in python 3.x