Page MenuHomeSoftware Heritage

cli: Register signal handlers for SIGTERM/SIGINT
ClosedPublic

Authored by olasd on Nov 15 2019, 1:25 PM.

Details

Summary

When run under a systemd service, the default stop command is to kill the
process; By default, Python doesn't trap sigterm and terminates the process
immediately, so even finally blocks don't run.

This traps SIGTERM and SIGINT (^C) signals and raises an exception, allowing the
process to exit in an orderly fashion.

Test Plan

It's not obvious how to actually test this. click.testing's CliRunner
doesn't support running commands in a separate thread, and running stuff in a
separate process is brittle as well.

Diff Detail

Repository
rDCORE Foundations and core functionalities
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.