diff options
author | Guy Streeter <streeter@redhat.com> | 2013-01-17 15:41:40 -0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-01-17 15:41:40 -0300 |
commit | cca561d2b28f3204cb2c2d17741370b613f83e49 (patch) | |
tree | 2fd12f8d3443edf5e10f95d537498735be552ea7 | |
parent | 07907b3dd533cb70bb4be2cdda4398c27f5d469e (diff) | |
download | tuna-cca561d2b28f3204cb2c2d17741370b613f83e49.tar.gz |
tuna: Catch OSError exceptions from python-schedutils
The python-schedutils package incorrectly raise SystemError instead of
OSError when a specified PID did not exist. It has since been corrected,
but tuna is still looking for the SystemError exception everywhere.
Look for both, so that tuna works with old and new versions, a followup
patch will tighten the handling, checking if the error is '3', no such
process, if not, re-raise the exception.
Signed-off-by: Guy Streeter <streeter@redhat.com>
[ committer note: Don't replace SystemError with OSError, handle both ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rwxr-xr-x | tuna-cmd.py | 6 | ||||
-rwxr-xr-x | tuna/gui/util.py | 4 | ||||
-rwxr-xr-x | tuna/tuna.py | 36 |
3 files changed, 23 insertions, 23 deletions
diff --git a/tuna-cmd.py b/tuna-cmd.py index cc45279..8fb986c 100755 --- a/tuna-cmd.py +++ b/tuna-cmd.py @@ -170,7 +170,7 @@ def ps_show_thread(pid, affect_children, ps, global irqs try: affinity = format_affinity(schedutils.get_affinity(pid)) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError return sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:] @@ -246,7 +246,7 @@ def ps_show(ps, affect_children, thread_list, cpu_list, continue try: affinity = schedutils.get_affinity(pid) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue if cpu_list and not set(cpu_list).intersection(set(affinity)): continue @@ -476,7 +476,7 @@ def main(): sys.exit(2) try: tuna.threads_set_priority(thread_list, a, affect_children) - except SystemError, err: + except (SystemError, OSError) as err: # (3, 'No such process') old python-schedutils incorrectly raised SystemError print "tuna: %s" % err sys.exit(2) elif o in ("-P", "--show_threads"): diff --git a/tuna/gui/util.py b/tuna/gui/util.py index eeb7616..ed46784 100755 --- a/tuna/gui/util.py +++ b/tuna/gui/util.py @@ -84,7 +84,7 @@ def thread_set_attributes(pid, threads, new_policy, new_prio, new_affinity, nr_c try: curr_affinity = schedutils.get_affinity(pid) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError return False try: @@ -105,7 +105,7 @@ def thread_set_attributes(pid, threads, new_policy, new_prio, new_affinity, nr_c try: curr_affinity = schedutils.get_affinity(pid) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError return False if curr_affinity != new_affinity: print _("couldn't change pid %(pid)d from %(caff)s to %(naff)s!") % \ diff --git a/tuna/tuna.py b/tuna/tuna.py index 290ff35..810d86c 100755 --- a/tuna/tuna.py +++ b/tuna/tuna.py @@ -166,7 +166,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None, try: try: curr_affinity = schedutils.get_affinity(pid) - except SystemError, e: + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError if e[0] == 3: # 'No such process' continue curr_affinity = None @@ -174,7 +174,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None, try: schedutils.set_affinity(pid, new_affinity) curr_affinity = schedutils.get_affinity(pid) - except SystemError, e: + except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError if e[0] == 3: # 'No such process' continue curr_affinity == None @@ -202,13 +202,13 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None, for tid in threads.keys(): try: curr_affinity = schedutils.get_affinity(tid) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue if set(curr_affinity) != set(new_affinity): try: schedutils.set_affinity(tid, new_affinity) curr_affinity = schedutils.get_affinity(tid) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue if set(curr_affinity) == set(new_affinity): changed = True @@ -218,7 +218,7 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None, print "move_threads_to_cpu: %s " % \ (_("could not change %(pid)d affinity to %(new_affinity)s") % \ {'pid':pid, 'new_affinity':new_affinity}) - except SystemError: + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError # process died continue return changed @@ -263,7 +263,7 @@ def move_irqs_to_cpu(cpus, irq_list, spread = False): pid = int(pid[0]) try: schedutils.set_affinity(pid, new_affinity) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError unprocessed.append(i) changed -= 1 continue @@ -287,14 +287,14 @@ def isolate_cpus(cpus, nr_cpus): continue try: affinity = schedutils.get_affinity(pid) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue if set(affinity).intersection(set(cpus)): previous_pid_affinities[pid] = copy.copy(affinity) affinity = affinity_remove_cpus(affinity, cpus, nr_cpus) try: schedutils.set_affinity(pid, affinity) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue if not ps[pid].has_key("threads"): @@ -305,14 +305,14 @@ def isolate_cpus(cpus, nr_cpus): continue try: affinity = schedutils.get_affinity(tid) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue if set(affinity).intersection(set(cpus)): previous_pid_affinities[tid] = copy.copy(affinity) affinity = affinity_remove_cpus(affinity, cpus, nr_cpus) try: schedutils.set_affinity(tid, affinity) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue del ps @@ -343,14 +343,14 @@ def include_cpus(cpus, nr_cpus): continue try: affinity = schedutils.get_affinity(pid) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue if set(affinity).intersection(set(cpus)) != set(cpus): previous_pid_affinities[pid] = copy.copy(affinity) affinity = list(set(affinity + cpus)) try: schedutils.set_affinity(pid, affinity) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue if not ps[pid].has_key("threads"): @@ -361,14 +361,14 @@ def include_cpus(cpus, nr_cpus): continue try: affinity = schedutils.get_affinity(tid) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue if set(affinity).intersection(set(cpus)) != set(cpus): previous_pid_affinities[tid] = copy.copy(affinity) affinity = list(set(affinity + cpus)) try: schedutils.set_affinity(tid, affinity) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue del ps @@ -414,7 +414,7 @@ def thread_filtered(tid, cpus_filtered, show_kthreads, show_uthreads): if cpus_filtered: try: affinity = schedutils.get_affinity(tid) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError return False if set(cpus_filtered + affinity) == set(cpus_filtered): @@ -453,14 +453,14 @@ def threads_set_priority(tids, parm, affect_children = False): for tid in tids: try: thread_set_priority(tid, policy, rtprio) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue if affect_children: for child in [int (a) for a in os.listdir("/proc/%d/task" % tid)]: if child != tid: try: thread_set_priority(child, policy, rtprio) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue class sched_tunings: @@ -489,7 +489,7 @@ def get_kthread_sched_tunings(proc = None): try: policy = schedutils.get_scheduler(pid) affinity = schedutils.get_affinity(pid) - except SystemError: # (3, 'No such process') + except (SystemError, OSError): # (3, 'No such process') old python-schedutils incorrectly raised SystemError continue percpu = iskthread(pid) and \ proc.is_bound_to_cpu(pid) |