Since you did not specify which HTTP server you are using (uWSGI, nginx, apache, etc.), you can test this recipe on a simple dev server.
- atexit , . , django builtin runserver.
runningerver.py $PATH_TO_YOUR_APP/management/commands/.
, PROCESSES_TO_KILL - , , .
import atexit
import signal
import sys
from django.core.management.commands.runserver import BaseRunserverCommand
class NewRunserverCommand(BaseRunserverCommand):
def __init__(self, *args, **kwargs):
atexit.register(self._exit)
signal.signal(signal.SIGINT, self._handle_SIGINT)
super(Command, self).__init__(*args, **kwargs)
def _exit(self):
for process in PROCESSES_TO_KILL:
process.terminate()
def _handle_SIGINT(signal, frame):
self._exit()
sys.exit(0)
, script, (, ).
, .