Django + mod_wsgi + apache2 - child process XXX still did not exit, sending a SIGTERM

I go by just P picture I go by just P · Nov 10, 2013 · Viewed 19.6k times · Source

I am getting intermittent errors -

child process XXX still did not exit, sending a SIGTERM.. and then a SIGKILL. It occurs intermittently and the web page hangs.

I was not using Daemon process..but now I am, still the problem exists..

Also I have some Error opening file for reading: Permission Denied.

Please can someone help?

I am new to this forum, so sorry if that has been answered before.

Answer

Graham Dumpleton picture Graham Dumpleton · Nov 10, 2013

If you were not using daemon mode of mod_wsgi, that would imply that Apache must have been restarted at the time that initial message was displayed.

What is occurring is that in trying to do a restart, Apache sends a SIGTERM to its child processes. If they do not exit by their own accord it will send SIGTERM again at 1 second intervals and finally send it a SIGKILL after 3 seconds. The message is warning you of the latter and that it force killed the process.

The issue now is what is causing the process to not shutdown promptly. There could be various reasons for this.

  • Using an extension module for Python which doesn't work in sub interpreters properly which is deadlocking and hanging the process, preventing it from shutting down. http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API

  • Use of background threads in the Python web application which have not been set as being daemon threads properly with the result they are then blocking process shutdown.

  • Your web application is simply trying to do too much on process shutdown somehow and not completing within the time limit.

Even if using daemon mode you will likely see this behaviour as it implements a similar shutdown timeout, albeit that the timeout is configurable for daemon mode.

Anyway, force use of the main Python interpreter as explained in the documentation link above

As to the permissions issue, read:

In short, ensure access permissions are correct of files/directories you need to access and ensure you are always using absolute path names when accessing the file system.