From 8e68e22757178879993d631dc514cf243a3d63ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Thu, 17 May 2018 10:58:17 +0200 Subject: [PATCH] Use the errno attribute of an exception instead of indices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Obtaining the errno from an exception using e[0] is not possible in Python3. Signed-off-by: Ondřej Lysoněk --- tuned/plugins/plugin_scheduler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tuned/plugins/plugin_scheduler.py b/tuned/plugins/plugin_scheduler.py index f504dc7..ee9f8b0 100644 --- a/tuned/plugins/plugin_scheduler.py +++ b/tuned/plugins/plugin_scheduler.py @@ -355,7 +355,7 @@ class SchedulerPlugin(base.Plugin): return schedutils.get_affinity(pid) # Workaround for old python-schedutils which incorrectly raised error except (SystemError, OSError) as e: - if e[0] == 3: + if hasattr(e, "errno") and e.errno == errno.ESRCH: log.debug("Unable to read affinity for PID %s, the task vanished." % pid) return None log.error("unable to get affinity for PID '%s': %s" % (str(pid), e)) @@ -367,7 +367,7 @@ class SchedulerPlugin(base.Plugin): schedutils.set_affinity(pid, affinity) # Workaround for old python-schedutils which incorrectly raised error except (SystemError, OSError) as e: - if e[0] == 3: + if hasattr(e, "errno") and e.errno == errno.ESRCH: log.debug("Unable to set affinity for PID %s, the task vanished." % pid) return False log.error("unable to set affinity '%s' for PID '%s': %s" % (str(affinity), str(pid), e))