Make SIGTERM timeout configurable via --sigterm-timeout and GLUETOOL_SIGTERM_TIMEOUT
Summary
The time gluetool waits for a child process to exit after sending it SIGTERM, before resorting to SIGKILL, was hardcoded to DEFAULT_SIGTERM_TIMEOUT (60 seconds).
This MR makes it configurable, resolved with the following precedence:
- the
sigterm-timeoutoption — set on the command line (--sigterm-timeout) or in a configuration file, - the
GLUETOOL_SIGTERM_TIMEOUTenvironment variable, following the existingGLUETOOL_TRACING_*convention, DEFAULT_SIGTERM_TIMEOUT(60s) when neither is set.
Changes
- Added the
SIGTERM_TIMEOUT_ENVVAR = 'GLUETOOL_SIGTERM_TIMEOUT'constant. - Added a module-level
sigterm_timeout(glue=None)helper that resolves the value following the precedence above. When aGlueinstance is passed it reads thesigterm-timeoutoption from it; otherwise the option is skipped. - Added the
sigterm-timeoutgluetooloption (type: int,default: None) so the timeout can be set on the command line or in a configuration file. - The
child.wait(...)call in theSIGTERM→SIGKILLescalation now usessigterm_timeout(Glue)instead of the constant directly. - Documented
GLUETOOL_SIGTERM_TIMEOUTin the--helpepilog alongside the other supported environment variables.
Usage
# via the command-line option (takes precedence)
gluetool --sigterm-timeout 120 ...
# via a configuration file
# [default]
# sigterm-timeout = 120
# via the environment variable
export GLUETOOL_SIGTERM_TIMEOUT=120 # wait 120s before sending SIGKILLTests
test_sigterm_timeout_default— falls back toDEFAULT_SIGTERM_TIMEOUTwhen neither the option nor the env var is set.test_sigterm_timeout_envvar(parametrized:0,1,120) — env var overrides the default.test_sigterm_timeout_envvar_invalid— a non-numeric env var raisesValueError.test_sigterm_timeout_option_overrides_envvar— the option takes precedence over the env var.test_sigterm_timeout_option_unset_falls_back_to_envvar— the env var is used when the option is unset.test_sigterm_timeout_option_unset_falls_back_to_default— the default is used when neither is set.test_sigterm_timeout_option_from_cmdline— the option is wired into the command-line parser and parsed as an integer.
Edited by Miroslav Vadkerti