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):
    pass
Django: How to run a function when server exits?