signals.py 628 B

123456789101112131415161718
  1. import os
  2. import signal
  3. def _handle_signal(signal_number, frame): # pragma: no cover
  4. '''
  5. Send the signal to all processes in borgmatic's process group, which includes child process.
  6. '''
  7. os.killpg(os.getpgrp(), signal_number)
  8. def configure_signals(): # pragma: no cover
  9. '''
  10. Configure borgmatic's signal handlers to pass relevant signals through to any child processes
  11. like Borg. Note that SIGINT gets passed through even without these changes.
  12. '''
  13. for signal_number in (signal.SIGHUP, signal.SIGTERM, signal.SIGUSR1, signal.SIGUSR2):
  14. signal.signal(signal_number, _handle_signal)