From 0c70baee8d3af97a130bc745adda85e530bd30b0 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Tue, 4 Dec 2018 01:36:19 +0100
Subject: [PATCH 2/2] tuna: Use exception args attribute for python3
In python3 exceptions are not interable, so use the args attribute
Signed-off-by: John Kacur <jkacur@redhat.com>
---
tuna-cmd.py | 4 ++--
tuna/gui/util.py | 4 ++--
tuna/tuna.py | 46 +++++++++++++++++++++++-----------------------
3 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 8068695ae6df..e4182231d80f 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -182,7 +182,7 @@ def ps_show_thread(pid, affect_children, ps,
try:
affinity = format_affinity(schedutils.get_affinity(pid))
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
return
raise e
@@ -264,7 +264,7 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
try:
affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if cpu_list and not set(cpu_list).intersection(set(affinity)):
diff --git a/tuna/gui/util.py b/tuna/gui/util.py
index 73eceae23ab7..9e30ed92bd4c 100755
--- a/tuna/gui/util.py
+++ b/tuna/gui/util.py
@@ -86,7 +86,7 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
try:
curr_affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ if e.args[0] == 3:
return False
raise e
@@ -109,7 +109,7 @@ def thread_set_attributes(pid_info, new_policy, new_prio, new_affinity, nr_cpus)
try:
curr_affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
- if e[0] == 3:
+ if e.args[0] == 3:
return False
raise e
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 9f9267863871..4b1a77bcfa9f 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -193,7 +193,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
try:
curr_affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
curr_affinity = None
raise e
@@ -202,7 +202,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
schedutils.set_affinity(pid, new_affinity)
curr_affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
curr_affinity == None
raise e
@@ -231,7 +231,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
try:
curr_affinity = schedutils.get_affinity(tid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if set(curr_affinity) != set(new_affinity):
@@ -239,7 +239,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
schedutils.set_affinity(tid, new_affinity)
curr_affinity = schedutils.get_affinity(tid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if set(curr_affinity) == set(new_affinity):
@@ -251,10 +251,10 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
(_("could not change %(pid)d affinity to %(new_affinity)s") % \
{'pid':pid, 'new_affinity':new_affinity}))
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
# process died
continue
- elif e[0] == errno.EINVAL: # unmovable thread)
+ elif e.args[0] == errno.EINVAL: # unmovable thread)
print("thread %(pid)d cannot be moved as requested" %{'pid':pid}, file=stderr)
continue
raise e
@@ -301,7 +301,7 @@ def move_irqs_to_cpu(cpus, irq_list, spread = False):
try:
schedutils.set_affinity(pid, new_affinity)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
unprocessed.append(i)
changed -= 1
continue
@@ -336,9 +336,9 @@ def isolate_cpus(cpus, nr_cpus):
try:
affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
- elif e[0] == errno.EINVAL:
+ elif e.args[0] == errno.EINVAL:
print("Function:", fname, ",", e.strerror, file=sys.stderr)
sys.exit(2)
raise e
@@ -348,9 +348,9 @@ def isolate_cpus(cpus, nr_cpus):
try:
schedutils.set_affinity(pid, affinity)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
- elif e[0] == errno.EINVAL:
+ elif e.args[0] == errno.EINVAL:
print("Function:", fname, ",", e.strerror, file=sys.stderr)
sys.exit(2)
raise e
@@ -364,9 +364,9 @@ def isolate_cpus(cpus, nr_cpus):
try:
affinity = schedutils.get_affinity(tid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
- elif e[0] == errno.EINVAL:
+ elif e.args[0] == errno.EINVAL:
print("Function:", fname, ",", e.strerror, file=sys.stderr)
sys.exit(2)
raise e
@@ -376,9 +376,9 @@ def isolate_cpus(cpus, nr_cpus):
try:
schedutils.set_affinity(tid, affinity)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
- elif e[0] == errno.EINVAL:
+ elif e.args[0] == errno.EINVAL:
print("Function:", fname, ",", e.strerror, file=sys.stderr)
sys.exit(2)
raise e
@@ -416,7 +416,7 @@ def include_cpus(cpus, nr_cpus):
try:
affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if set(affinity).intersection(set(cpus)) != set(cpus):
@@ -425,7 +425,7 @@ def include_cpus(cpus, nr_cpus):
try:
schedutils.set_affinity(pid, affinity)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
@@ -438,7 +438,7 @@ def include_cpus(cpus, nr_cpus):
try:
affinity = schedutils.get_affinity(tid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if set(affinity).intersection(set(cpus)) != set(cpus):
@@ -447,7 +447,7 @@ def include_cpus(cpus, nr_cpus):
try:
schedutils.set_affinity(tid, affinity)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
@@ -515,7 +515,7 @@ def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads):
try:
affinity = schedutils.get_affinity(tid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
return False
raise e
@@ -554,7 +554,7 @@ def threads_set_priority(tids, parm, affect_children = False):
try:
thread_set_priority(tid, policy, rtprio)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
if affect_children:
@@ -563,7 +563,7 @@ def threads_set_priority(tids, parm, affect_children = False):
try:
thread_set_priority(child, policy, rtprio)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
@@ -594,7 +594,7 @@ def get_kthread_sched_tunings(proc = None):
policy = schedutils.get_scheduler(pid)
affinity = schedutils.get_affinity(pid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised SystemError
- if e[0] == errno.ESRCH:
+ if e.args[0] == errno.ESRCH:
continue
raise e
percpu = iskthread(pid) and \
--
2.19.2