In short, there is no such thing. In the most common scenario
(including yours, based on your email), Django is used as a WSGI
application, which starts up once, and then lives inside an
application server, which listens to requests, and translates them
into function calls. In that sense, Django is more of a passive thing,
that waits to be called with a request, which it then dutifully
processes, and finally enters the waiting state again. This happens
until the application server itself exits, but that is out of the
scope of what Django does.
Usually, application servers also just run indefinitely, until they
are killed. Or you can configure them to only run for a certain amount
of time. Or you can set them up to quit and restart after they process
a certain number of requests. Either way, the shutdown sequence
usually consists of just terminating the process.
What you are asking for sounds like it falls into the responsibility
of your application server. For example, Gunicorn has an ``on_exit``
hook [1], or if you're using uwsgi, it also has some hooks [2], though
I haven't been able to extract much useful information at a glance,
but you might be able to find something that suits your need.
Cheers,
Michal
[1]:
http://docs.gunicorn.org/en/latest/settings.html#on-exit
[2]:
https://uwsgi-docs.readthedocs.io/en/latest/Hooks.html