I experimented with multiprocessing and worked in mindblock with daemons.
I have one daemon and one non-demon process, each of which gives an output every second endlessly, while the non-demon prints the output immediately after starting, sleeping for 3 seconds, then prints and returns again.
The problem is that the expected result of the daemon process is not displayed at all.
Reviewing past SO issues on daemons, common problems seem to be either other processes ending before the daemon, or stdout requiring a reset to output output. Both (I think) were considered, however, I continue to see only printed materials from non-demonic processes.
Code:
from multiprocessing import Process, current_process import sys import time def worker(): """ Announce that the process has started, sleep 3 seconds then announce that the process is ending. """ name = current_process().name print name, 'starting...' sys.stdout.flush() time.sleep(3) print name, 'ending...' sys.stdout.flush() return def daemon(): """ Announce that the process has started, beep, then beep once every second """ name = current_process().name print name, 'starting...' print 'beep...' sys.stdout.flush() while True: time.sleep(1) print 'beep...' sys.stdout.flush() if __name__=='__main__': d = Process(target=daemon) d.daemon = True d.start() p = Process(target=worker) p.daemon = False p.start()
Expected Result:
Process-1 starting... # Order here may vary beep... Process-2 starting... beep... beep... Process-2 ending... #There may or may not be another beep here
What really turns out:
Process-2 starting... Process-2 ending...
Any advice on why this is happening will be truly appreciated.
source share