I've built a website using CherryPy, Apache, and mod_wsgi, and everything's great except for one problem. When a user action calls for an email to be automatically sent, I sometimes use os.fork
so that the parent process can return immediately and give the user an "OK" message, while the child process is in charge of sending the email (which may take several seconds, and I don't want the user to have to wait for that).
The problem arises when the child process has finished its job and calls sys.exit()
. It seems that mod_wsgi catches the SystemExit
exception, dumps the traceback into my Apache error log, and keeps the child process running. I have two problems with this:
It clutters up the Apache error log with a traceback that does NOT represent anything having actually gone WRONG, and
It leaves the process running, wasting system resources. Worse, how many of these sleeping processes are going to accumulate over time?
For the record, the output in the Apache error log looks like this:
mod_wsgi (pid=14900): SystemExit exception raised by WSGI script '/Users/me/myscript.py' ignored.
followed by the traceback leading up to the sys.exit() call.
I guess this explains why the SystemExit
exception is caught by mod_wsgi, but that doesn't help me.
It would be great if there were a way to configure mod_wsgi's behaviour in regards to this, yet when I searched for both "SystemExit" and "sys.exit" in the docs, neither one turned up anything.
Searching for "mod_wsgi SystemExit" on this site yields only six posts, and none of them is asking how to allow a child process to exit.
Does anyone know how I can get the child processes to actually exit, and make mod_wsgi NOT dump anything into the Apache error log?