I need to spawn a background process in django, the view returns immediately, the background process continues make some changes, then update the db. This is done by os.spawnl() function to call a separate .py file.
The problem is after the background process is done, it becames a zombie function [python] <defunct>.
How do I avoid that? I followed this and this example but I still got the child process as zombie after the django render process.
I want to take this chance to practice my *nix process management skills so please do me a favor, don’t give me Celery or other mq/async task solutions, and I hate dependencies.
This got to long for a comment-
The
waitsyscall (whichos.waitis a wrapper for) reaps exit codes/pids from dead processes. You will want toos.waitin the process that is a generation above your zombie processes; the parent of the zombies processes. The parent processes will receive aSIGCHLDsignal when one of its child processes die. If you insist on doing all of this yourself, you will need to install a signal handler to trap forSIGCHLDand in the signal handler callos.wait. Read some documentation on unix process handling and the Python documentation on theosmodule as there are variations of theos.waitfunction that will be non-blocking which maybe helpful.