From 803a5494ef23187e920eeb4b42e922b87cda5966 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 18 May 2022 07:18:51 -0400 Subject: fix: the SIGTERM handler is now opt-in. #1310 --- coverage/config.py | 2 ++ coverage/control.py | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'coverage') diff --git a/coverage/config.py b/coverage/config.py index 1571c017..1ad46597 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -190,6 +190,7 @@ class CoverageConfig: self.relative_files = False self.run_include = None self.run_omit = None + self.sigterm = False self.source = None self.source_pkgs = [] self.timid = False @@ -364,6 +365,7 @@ class CoverageConfig: ('relative_files', 'run:relative_files', 'boolean'), ('run_include', 'run:include', 'list'), ('run_omit', 'run:omit', 'list'), + ('sigterm', 'run:sigterm', 'boolean'), ('source', 'run:source', 'list'), ('source_pkgs', 'run:source_pkgs', 'list'), ('timid', 'run:timid', 'boolean'), diff --git a/coverage/control.py b/coverage/control.py index 6387d0dd..a0571c97 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -536,12 +536,13 @@ class Coverage: # Register our clean-up handlers. atexit.register(self._atexit) - is_main = (threading.current_thread() == threading.main_thread()) - if is_main and not env.WINDOWS: - # The Python docs seem to imply that SIGTERM works uniformly even - # on Windows, but that's not my experience, and this agrees: - # https://stackoverflow.com/questions/35772001/x/35792192#35792192 - self._old_sigterm = signal.signal(signal.SIGTERM, self._on_sigterm) + if self.config.sigterm: + is_main = (threading.current_thread() == threading.main_thread()) + if is_main and not env.WINDOWS: + # The Python docs seem to imply that SIGTERM works uniformly even + # on Windows, but that's not my experience, and this agrees: + # https://stackoverflow.com/questions/35772001/x/35792192#35792192 + self._old_sigterm = signal.signal(signal.SIGTERM, self._on_sigterm) def _init_data(self, suffix): """Create a data file if we don't have one yet.""" -- cgit v1.2.1