6

I overrode BaseCommand to create my own management command, as documented here. It's a long-running process though, and I want to be able to interrupt it and have it gracefully shut down when I send it ctrl+c.

I tried the usual signal.signal(signal.SIGINT, signal_handler), but the signal_handler never gets called. Django seems to have its own signal handling system, but I made responders for the three django.core.signals: got_request_exception, request_finished, and request_started but none of those get called either.

frank
  • 1,322
  • 1
  • 10
  • 28
  • Possibly related to http://stackoverflow.com/q/5789642/400691 ? – meshy Sep 26 '14 at 21:16
  • 2
    Django signals don't have anything at all to do with OS signals. – Daniel Roseman Sep 26 '14 at 22:02
  • @meshy usually the [signal library](https://docs.python.org/2/library/signal.html) works to catch the SIGINT signal that's raised by a ctrl+c. – frank Sep 26 '14 at 22:58
  • @DanielRoseman thanks, I figured as much. Considering the amount of jargon one must familiarize themselves with to get acquainted with the Django platform, you think they'd come up with their own terminology for a completely different system sharing the same namespace. :) – frank Sep 26 '14 at 23:00
  • 3
    Old question but actually standard python signal handling does work in management commands. Just checked it for python 3.5.1 and django 1.11.2. – and Dec 07 '17 at 14:18

0 Answers0