refactor: replace bare except blocks with Exception for better signal handling

This commit is contained in:
limuthu123 2026-05-31 01:37:29 +05:30
parent c6cf3de292
commit eba577358e
7 changed files with 9 additions and 9 deletions

View file

@ -202,11 +202,11 @@ after = 1.conf
rplcmnt = 1
try: # set it in map-vars (consider different python versions):
defaults[sopt] = v
except:
except Exception:
# try to set in first default map (corresponding vars):
try:
defaults._maps[0][sopt] = v
except: # pragma: no cover
except Exception: # pragma: no cover
# no way to update vars chain map - overwrite defaults:
self._defaults[sopt] = v
return rplcmnt

View file

@ -36,7 +36,7 @@ import importlib
try:
import ctypes
_libcap = ctypes.CDLL('libcap.so.2')
except:
except Exception:
_libcap = None

View file

@ -94,7 +94,7 @@ R_MAP = {
try:
re.search("^re(?i:val)$", "reVAL")
R_GLOB2LOCFLAGS = ( re.compile(r"(?<!\\)\((?:\?:)?(\(\?[a-z]+)\)"), r"\1:" )
except:
except Exception:
R_GLOB2LOCFLAGS = ()
def mapTag2Opt(tag):

View file

@ -1314,7 +1314,7 @@ try:
md5sum = hashlib.md5
# try to use it (several standards like FIPS forbid it):
md5sum(' ').hexdigest()
except: # pragma: no cover
except Exception: # pragma: no cover
md5sum = hashlib.sha1
except ImportError: # pragma: no cover
# hashlib was introduced in Python 2.5. For compatibility with those

View file

@ -194,7 +194,7 @@ class FilterSystemd(JournalFilter): # pragma: systemd no cover
ja = self.__jrnlargs
super(journal.Reader, self.__journal).__init__(
ja.get('flags', 0), ja.get('path'), ja.get('files'), ja.get('namespace'))
except:
except Exception:
# cannot reopen in that way, so simply recreate reader:
self.closeJournal()
self.__journal = journal.Reader(**self.__jrnlargs)

View file

@ -204,7 +204,7 @@ class DNSUtils:
# try to obtain from network interfaces if possible (implemented for this platform):
try:
ips = IPAddrSet([a for ni, a in DNSUtils._NetworkInterfacesAddrs()])
except:
except Exception:
ips = IPAddrSet()
# cache and return :
DNSUtils.CACHE_nameToIp.set(DNSUtils._getNetIntrfIPs_key, ips)
@ -257,7 +257,7 @@ class DNSUtils:
with open('/proc/sys/net/ipv6/conf/all/disable_ipv6', 'rb') as f:
# if 1 - disabled, 0 - enabled
return not int(f.read())
except:
except Exception:
pass
s = None
try:

View file

@ -939,7 +939,7 @@ class Server:
os.close(fd)
except OSError: # ERROR (ignore)
pass
except:
except Exception:
try:
maxfd = os.sysconf("SC_OPEN_MAX")
except (AttributeError, ValueError):