From f5b2a9fcc633f52a6d8eb2b25790ea5f0d1af856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 13 Feb 2022 22:39:26 +0100 Subject: [PATCH] add 'signals-ignore' option (#2296) --- docs/configuration.rst | 12 ++++++++++++ gallery_dl/__init__.py | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index ad2bbab8..f6f547c6 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -3308,6 +3308,18 @@ Description this cache. +signals-ignore +-------------- +Type + ``list`` of ``strings`` +Example + ``["SIGTTOU", "SIGTTIN", "SIGTERM"]`` +Description + The list of signal names to ignore, i.e. set + `SIG_IGN `_ + as signal handler for. + + pyopenssl --------- Type diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index ad8286ed..0214659a 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2014-2021 Mike Fährmann +# Copyright 2014-2022 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -131,6 +131,19 @@ def main(): for opts in args.options: config.set(*opts) + # signals + signals = config.get((), "signals-ignore") + if signals: + import signal + if isinstance(signals, str): + signals = signals.split(",") + for signal_name in signals: + signal_num = getattr(signal, signal_name, None) + if signal_num is None: + log.warning("signal '%s' is not defined", signal_name) + else: + signal.signal(signal_num, signal.SIG_IGN) + # extractor modules modules = config.get(("extractor",), "modules") if modules is not None: