This might be a non-answer depending on your apache config. However, most apache mod_wsgi configs recommend you implement some sort of max_requests before restarting the wsgi process. Its possible your code is doing this either based off normal requests, or perhaps your code is hitting a django exception.
In both cases, you should be able to tell this by apache config or options alone.
restart-interval=sss
Defines a time limit in seconds for how long a
daemon process should run before being restarted.
This might be use to periodically force restart the WSGI application
processes when you have issues related to Python object reference
count cycles, or incorrect use of in memory caching, which causes
constant memory growth.
If this option is not defined, or is defined to be 0, then the daemon
process will be persistent and will continue to service requests until
Apache itself is restarted or shutdown.
Avoid setting this too low. This is because the constant restarting
and reloading of your WSGI application may cause unecessary load on
your system and affect performance.
You can use the graceful-timeout option in conjunction with this
option to reduce the chances that an active request will be
interrupted when a restart occurs due to the use of this option.
maximum-requests=nnn
Defines a limit on the number of requests a
daemon process should process before it is shutdown and restarted.
This might be use to periodically force restart the WSGI application
processes when you have issues related to Python object reference
count cycles, or incorrect use of in memory caching, which causes
constant memory growth.
If this option is not defined, or is defined to be 0, then the daemon
process will be persistent and will continue to service requests until
Apache itself is restarted or shutdown.
Avoid setting this to a low number of requests on a site which handles
a lot of traffic. This is because the constant restarting and
reloading of your WSGI application may cause unecessary load on your
system and affect performance. Only use this option if you have no
other choice due to a memory usage issue. Stop using it as soon as any
memory issue has been resolved.
You can use the graceful-timeout option in conjunction with this
option to reduce the chances that an active request will be
interrupted when a restart occurs due to the use of this option.
inactivity-timeout=sss
Defines the maximum number of seconds allowed
to pass before the daemon process is shutdown and restarted when the
daemon process has entered an idle state. For the purposes of this
option, being idle means there are no currently active requests and no
new requests are being received.
This option exists to allow infrequently used applications running in
a daemon process to be restarted, thus allowing memory being used to
be reclaimed, with process size dropping back to the initial startup
size before any application had been loaded or requests processed.
Note that after any restart of the WSGI application process, the WSGI
application will need to be reloaded. This can mean that the first
request received by a process after the process was restarted can be
slower. If you WSGI application has a very high startup cost on CPU
and time, it may not be a good idea to use the option.
See also the request-timeout option for forcing a process restart when
requests block for a specified period of time.
Note that similar functionality to that of the request-timeout option,
for forcing a restart when requests blocked, was part of what was
implemented by the inactivity-timeout option. The request timeout was
broken out into a separate feature in version 4.1.0 of mod_wsgi.
request-timeout=sss
Defines the maximum number of seconds that a
request is allowed to run before the daemon process is restarted. This
can be used to recover from a scenario where a request blocks
indefinitely, and where if all request threads were consumed in this
way, would result in the whole WSGI application process being blocked.
How this option is seen to behave is different depending on whether a
daemon process uses only one thread, or more than one thread for
handling requests, as set by the threads option.
If there is only a single thread, and so the process can only handle
one request at a time, as soon as the timeout has passed, a restart of
the process will be initiated.
If there is more than one thread, the request timeout is applied to
the average running time for any requests, across all threads. This
means that a request can run longer than the request timeout. This is
done to reduce the possibility of interupting other running requests,
and causing a user to see a failure. So where there is still capacity
to handle more requests, restarting of the process will be delayed if
possible.
deadlock-timeout=sss
Defines the maximum number of seconds allowed to
pass before the daemon process is shutdown and restarted after a
potential deadlock on the Python GIL has been detected. The default is
300 seconds.
This option exists to combat the problem of a daemon process freezing
as the result of a rogue Python C extension module which doesn’t
properly release the Python GIL when entering into a blocking or long
running operation.
startup-timeout=sss
Defines the maximum number of seconds allowed to
pass waiting to see if a WSGI script file can be loaded successfully
by a daemon process. When the timeout is passed, the process will be
restarted.
This can be used to force the reloading of a process when a transient
issue occurs on the first attempt to load the WSGI script file, but
subsequent attempts still fail because a Python package that was
loaded has retained state that prevents attempts to run initialisation
a second time within the same process. The Django package can cause
this scenario as the initialisation of Django itself can no longer be
attempted more than once in the same process.
.ready()
should be called only once, by the first thread that's ready, as you can see here: github.com/django/django/blob/master/django/apps/… At the end of the block, the.ready
property is set totrue
to prevent it from being run again. Did your web server maybe restart and that restarted the Django app? – C14L Sep 23 '19 at 19:19.ready()
is called the second time. – Serge Rogatch Sep 24 '19 at 5:47