diff options
author | Paul Wicks <pwicks86@gmail.com> | 2018-07-10 13:38:27 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2020-01-05 16:07:47 -0800 |
commit | 0c579fba83d55e2ee4acc8362a1be2beae86ad56 (patch) | |
tree | 5f01c5a7eb09cb7b57958a3fbc77ce8e3e87dd4d /gnuradio-runtime/python/gnuradio | |
parent | cf0e4a4e0a39b36737049c1b2239a5209ff17f9d (diff) |
Remove catch statements from thread_body_wrapper.h
This commit removes the catch statements from thread_body_wrapper.h.
The reason to do this is that, as-is, a single block in a flowgraph
may throw an exception and stop functioning, but the only indication
of this to the user is printing the exception's what() to stderr.
With this patch, any uncaught exception will call std::terminate,
which should still print the exception's what(), but will also
terminate the process, rather than leaving a zombie flowgraph.
Diffstat (limited to 'gnuradio-runtime/python/gnuradio')
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gr/qa_uncaught_exception.py | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_uncaught_exception.py b/gnuradio-runtime/python/gnuradio/gr/qa_uncaught_exception.py new file mode 100644 index 0000000000..18799d152d --- /dev/null +++ b/gnuradio-runtime/python/gnuradio/gr/qa_uncaught_exception.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# +# Copyright 2018 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest, blocks +from multiprocessing import Process +import numpy + + +# This block just exists to pass data through and throw an exception +class except_block(gr.sync_block): + def __init__(self, throw_except, except_count=10000): + gr.sync_block.__init__( + self, + name="except_block", + in_sig=[numpy.complex64], + out_sig=[numpy.complex64], + ) + self.throw_except = throw_except + self.except_count = except_count + self.count = 0 + + def work(self, input_items, output_items): + output_items[0][:] = input_items[0] + self.count += len(output_items[0]) + if self.count >= self.except_count: + raise RuntimeError("Error in except_block") + return len(output_items[0]) + + +class test_uncaught_exception(gr_unittest.TestCase): + + def test_exception_throw(self): + # Test to ensure that throwing an exception causes the + # process running top_block to exit + + def process_func(): + tb = gr.top_block() + # some test data + src_data = [complex(x, x + 1) for x in range(65536)] + src = blocks.vector_source_c(src_data) + src.set_repeat(True) + + e_block_1 = except_block(False) + e_block_2 = except_block(True) + + sink_1 = blocks.null_sink(gr.sizeof_gr_complex) + sink_2 = blocks.null_sink(gr.sizeof_gr_complex) + + tb.connect(src, e_block_1) + tb.connect(src, e_block_2) + tb.connect(e_block_1, sink_1) + tb.connect(e_block_2, sink_2) + tb.run() + + p = Process(target=process_func) + p.daemon = True + p.start() + p.join(1) + exit_code = p.exitcode + self.assertIsNotNone( + exit_code, "exception did not cause flowgraph exit") + +if __name__ == '__main__': + gr_unittest.run(test_uncaught_exception, "test_uncaught_exception.xml") |