diff options
author | Brennan Ashton <bashton@brennanashton.com> | 2018-11-14 17:53:22 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2018-11-15 15:44:05 -0800 |
commit | 2f66412afaca4a42319c666958c89827edd8f2f3 (patch) | |
tree | f82482c09d4885fcd8b1a279484d5770767a32aa | |
parent | 39b74849d939456a0d1e4aa534e9f829e742ba63 (diff) |
gr-runtime: Improve exception handling in ControlPort Monitor
-rw-r--r-- | gnuradio-runtime/python/gnuradio/ctrlport/monitor.py | 17 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/eng_arg.py | 4 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/eng_notation.py | 9 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/eng_option.py | 4 | ||||
-rw-r--r-- | gnuradio-runtime/python/pmt/pmt_to_python.py | 3 |
5 files changed, 20 insertions, 17 deletions
diff --git a/gnuradio-runtime/python/gnuradio/ctrlport/monitor.py b/gnuradio-runtime/python/gnuradio/ctrlport/monitor.py index 87d6cb9e7f..0cc05be63e 100644 --- a/gnuradio-runtime/python/gnuradio/ctrlport/monitor.py +++ b/gnuradio-runtime/python/gnuradio/ctrlport/monitor.py @@ -33,15 +33,12 @@ class monitor(object): self.tool = tool atexit.register(self.shutdown) - try: - # setup export prefs - gr.prefs().singleton().set_bool("ControlPort","on",True); - if(tool == "gr-perf-monitorx"): - gr.prefs().singleton().set_bool("ControlPort","edges_list",True); - gr.prefs().singleton().set_bool("PerfCounters","on",True); - gr.prefs().singleton().set_bool("PerfCounters","export",True); - except: - print("no support for gr.prefs setting") + # setup export prefs + gr.prefs().singleton().set_bool("ControlPort","on",True); + if(tool == "gr-perf-monitorx"): + gr.prefs().singleton().set_bool("ControlPort","edges_list",True); + gr.prefs().singleton().set_bool("PerfCounters","on",True); + gr.prefs().singleton().set_bool("PerfCounters","export",True); def __del__(self): if(self.started): @@ -57,7 +54,7 @@ class monitor(object): print("running: %s"%(str(cmd))) self.proc = subprocess.Popen(cmd); self.started = True - except: + except (ValueError, OSError): self.proc = None print("failed to to start ControlPort Monitor on specified port") diff --git a/gnuradio-runtime/python/gnuradio/eng_arg.py b/gnuradio-runtime/python/gnuradio/eng_arg.py index 5983352443..f620e34b1f 100644 --- a/gnuradio-runtime/python/gnuradio/eng_arg.py +++ b/gnuradio-runtime/python/gnuradio/eng_arg.py @@ -34,7 +34,7 @@ def intx(string): """ try: return int(string, 0) - except: + except (ValueError, TypeError): raise argparse.ArgumentTypeError( "Invalid integer value: {}".format(string) ) @@ -47,7 +47,7 @@ def eng_float(string): """ try: return eng_notation.str_to_num(string) - except: + except (TypeError, ValueError): raise argparse.ArgumentTypeError( "Invalid engineering notation value: {}".format(string) ) diff --git a/gnuradio-runtime/python/gnuradio/eng_notation.py b/gnuradio-runtime/python/gnuradio/eng_notation.py index 391dc5838f..ec35b0db5b 100644 --- a/gnuradio-runtime/python/gnuradio/eng_notation.py +++ b/gnuradio-runtime/python/gnuradio/eng_notation.py @@ -23,6 +23,9 @@ Display numbers as strings using engineering notation. """ from __future__ import unicode_literals +import six + + scale_factor = {} scale_factor['E'] = 1e18 scale_factor['P'] = 1e15 @@ -66,11 +69,13 @@ def num_to_str (n, precision=6): def str_to_num (value): '''Convert a string in engineering notation to a number. E.g., '15m' -> 15e-3''' try: + if not isinstance(value, six.string_types): + raise TypeError("Value must be a string") scale = 1.0 suffix = value[-1] if suffix in scale_factor: return float (value[0:-1]) * scale_factor[suffix] return float (value) - except: - raise RuntimeError ( + except (TypeError, KeyError, ValueError): + raise ValueError ( "Invalid engineering notation value: %r" % (value,)) diff --git a/gnuradio-runtime/python/gnuradio/eng_option.py b/gnuradio-runtime/python/gnuradio/eng_option.py index 565780be28..51add1499e 100644 --- a/gnuradio-runtime/python/gnuradio/eng_option.py +++ b/gnuradio-runtime/python/gnuradio/eng_option.py @@ -30,14 +30,14 @@ from . import eng_notation def check_eng_float (option, opt, value): try: return eng_notation.str_to_num(value) - except: + except (ValueError, TypeError): raise OptionValueError ( "option %s: invalid engineering notation value: %r" % (opt, value)) def check_intx (option, opt, value): try: return int (value, 0) - except: + except (ValueError, TypeError): raise OptionValueError ( "option %s: invalid integer value: %r" % (opt, value)) diff --git a/gnuradio-runtime/python/pmt/pmt_to_python.py b/gnuradio-runtime/python/pmt/pmt_to_python.py index 270a1dd9e9..ddadb6a89c 100644 --- a/gnuradio-runtime/python/pmt/pmt_to_python.py +++ b/gnuradio-runtime/python/pmt/pmt_to_python.py @@ -124,7 +124,8 @@ def pmt_to_python(p): if pmt_check(p): try: return to_python(p) - except: + except (TypeError, ValueError): + # This exception will be handled by the general failure case pass raise ValueError("can't convert %s type to pmt (%s)"%(type(p),p)) |