python - Multiprocess Daemon Not Terminating on Parent Exit -


i have python 2.7 multiprocessing process not exit on parent process exit. i've set daemon flag should force exit on parent death. docs state that:

"when process exits, attempts terminate of daemonic child processes."

p = process(target=_serverlaunchhelper, args=args) p.daemon = true print p.daemon # prints true p.start() 

when terminate parent process via kill command daemon left alive , running (which blocks port on next run). child process starting simplehttpserver , calling serve_forever without doing else. guess "attempts" part of docs means blocking server process stopping process death , it's letting process orphaned result. have child push serving thread , have main thread check parent process id changes, seems lot of code replicate daemon functionality.

does have insight why daemon flag isn't working described? repeatable on windows8 64 bit , ubuntu12 32 bit vm.

a boiled down version of process function below:

def _serverlaunchhelper(port)     httpd = socketserver.tcpserver(("", port), handler)     httpd.serve_forever() 

when process exits, attempts terminate of daemonic child processes.

the key word here "attempts". also, "exits".

depending on platform , implementation, may way daemonic child processes terminated explicitly. if parent process exits normally, gets chance explicitly, fine. if parent process terminated abruptly, doesn't.

for cpython in particular, if @ the source, terminating daemonic processes handled same way joining non-daemonic processes: walking active_children() in atexit function. so, daemons killed if , if atexit handlers run. and, module's docs say:

note: functions registered via module not called when program killed signal not handled python, when python fatal internal error detected, or when os._exit() called.

depending on how you're killing parent, might able work around adding signal handler intercept abrupt termination. might not—e.g., on posix, sigkill not intercept able, if kill -9 $parentpid, isn't option.

another option kill process group, instead of parent process. example, if parent has pid 12345, kill -- -12345 on linux kill , of children (assuming haven't done fancy).


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -