mod_wsgi process getting killed and django stops working

2024/11/15 7:50:50

I have mod_wsgi running in daemon mode on a custom Linux build. I haven't included any number for processes or threads in the apache config. Here is my config:

WSGIDaemonProcess django user=admin
WSGIProcessGroup django
WSGIScriptAlias /django_apps /django/apache/django.wsgi
WSGIApplicationGroup %{GLOBAL}

On the system, there is a httpd cleanup process running which kills any httpd process that exceeds a certain memory threshold.

It looks like the httpd process which is running mod_wsgi is getting killed. Afterwards, the django portion of my website stops working.

I get this error message:

Script timed out before returning headers: django.wsgi

Every time I access a django page, I get these log messages:

<6> Jul  7 10:13:11 httpd[12598]: [info] mod_wsgi (pid=12598): Initializing Python.
<6> Jul  7 10:13:11 httpd[12598]: [info] mod_wsgi (pid=12598): Attach interpreter ''.
<6> Jul  7 10:13:16 httpd[12638]: [info] mod_wsgi (pid=12638): Attach interpreter ''.
<6> Jul  7 10:13:17 httpd[12615]: [info] mod_wsgi (pid=12615): Destroying interpreters.
<6> Jul  7 10:13:17 httpd[12615]: [info] mod_wsgi (pid=12615): Cleanup interpreter ''.
<6> Jul  7 10:13:17 httpd[12615]: [info] mod_wsgi (pid=12615): Terminating Python.
<6> Jul  7 10:13:17 httpd[12615]: [info] mod_wsgi (pid=12615): Python has shutdown.

Can anybody help me understand what is going here. Why does the mod_wsgi process fail to restart? How do I configure it to restart gracefully?

Thanks very much in advance.

Answer

For a start, read:

http://blog.dscpl.com.au/2009/11/save-on-memory-with-modwsgi-30.html

and disable initialisation of Python interpreter within embedded processes if only using daemon mode. Those log messages are likely from embedded processes and showing up because of overly aggressive settings for Apache MPM that cause main Apache child processes to be started up and shutdown to much. Disable the unused interpreters and likely those messages will go away.

This issue though is separate to your problem with the daemon mode process.

For that, set on WSGIDaemonProcess the 'display-name=%{GROUP}' option. This will cause daemon mode process to show as '(wsgi:django)' in 'ps' output listing. That way you can clearly identify which process it is.

Then when your process killer kicks in use 'ps' to verify the state of the process and whether there is actually one and whether it shutdown properly. What may be happening is that process is refusing to shutdown because it is hanging on waiting for some child process to shutdown or stuck on some remote file system operation. Alternatively, the code is registering a signal handler which is interfering with correct shutdown.

If that process doesn't shutdown properly it will not be replaced, yet the initiation of a shutdown may put it in to a state where by it doesn't accept new requests either.

So, start with that and report back what you find.

BTW, there is an official mod_wsgi mailing list. StackOverflow is a poor medium for back and forth debugging of problems like this.

https://en.xdnf.cn/q/71970.html

Related Q&A

Reindex 2nd level in incomplete multi-level dataframe to be complete, inserting NANs on missing rows

I need to reindex the 2nd level of a pandas dataframe, so that the 2nd level becomes a (complete) list 0,...,(N-1) for each 1st level index.I tried using Allan/Haydens approach, but unfortunately it on…

ImportError: cannot import name _gdal_array from osgeo

I create a fresh environment, install numpy, then install GDAL. GDAL imports successfully and I can open images using gdal.Open(, but I get the ImportError: cannot import name _gdal_array from osgeo er…

How do I insert a map into DynamoDB table?

I have the following line of code :table.put_item( Item={filename : key, status : {M : iocheckdict }})The iocheckdict looks like this:{A: One, C: Three, D: Four, B: Two, E: Five}So, when I am running t…

How to redirect django.contrib.auth.views.login after login?

I added django.contrib.auth.views.login everywhere in my webpage, for that I had to load a templatetag (that returns the AuthenticationForm) in my base.html. This templatetags includes the registration…

How to do windows API calls in Python 3.1?

Has anyone found a version of pywin32 for python 3.x? The latest available appears to be for 2.6.Alternatively, how would I "roll my own" windows API calls in Python 3.1?

Returning the outputs from a CloudFormation template with Boto?

Im trying to retrieve the list of outputs from a CloudFormation template using Boto. I see in the docs theres an object named boto.cloudformation.stack.Output. But I think this is unimplemented functi…

numpy.array of an I;16 Image file

I want to use TIFF images to effectively save large arrays of measurement data. With setting them to mode="I;16" (corresponding to my 16 bit data range), they yield 2MB files (~1000x1000 &quo…

Namespace packages and pip install -e

I have a ns.pkg2 package that depends on ns.pkg1 package. I make a fork of it, publish it to git and want to install my version into my virtualenv. I use pip install -e mygit and end up with ns.pkg in …

Python sys.argv out of range, dont understand why

I have a script that Ive been using for a some time to easily upload files to my server. It has been working great for a long time, but I cant get it to work on my new desktop computer. The code is sim…

Error calling BashOperator: Bash command failed

Here are my dag file and BashOperator task:my_dag = { dag_id = my_dag, start_date = datetime(year=2017, month=3, day=28), schedule_interval=01***, }my_bash_task = BashOperator( task_id="my_bash_t…