void stop() throw (std::runtime_error);
void wait() throw (std::runtime_error);
};
+
+%{
+class ensure_py_gil_state2 {
+ PyGILState_STATE d_gstate;
+public:
+ ensure_py_gil_state2() { d_gstate = PyGILState_Ensure(); }
+ ~ensure_py_gil_state2() { PyGILState_Release(d_gstate); }
+};
+%}
+
+%inline %{
+void runtime_run_unlocked(gr_runtime_sptr r) throw (std::runtime_error)
+{
+ ensure_py_gil_state2 _lock;
+ r->run();
+}
+
+void runtime_start_unlocked(gr_runtime_sptr r) throw (std::runtime_error)
+{
+ ensure_py_gil_state2 _lock;
+ r->start();
+}
+
+void runtime_stop_unlocked(gr_runtime_sptr r) throw (std::runtime_error)
+{
+ ensure_py_gil_state2 _lock;
+ r->stop();
+}
+
+void runtime_wait_unlocked(gr_runtime_sptr r) throw (std::runtime_error)
+{
+ ensure_py_gil_state2 _lock;
+ r->wait();
+}
+
+%}
# Boston, MA 02110-1301, USA.
#
-from gnuradio_swig_python import hier_block2_swig, gr_make_runtime
+from gnuradio_swig_python import hier_block2_swig, gr_make_runtime, \
+ runtime_run_unlocked, runtime_start_unlocked, runtime_stop_unlocked, \
+ runtime_wait_unlocked
#
# This hack forces a 'has-a' relationship to look like an 'is-a' one.
self._r = gr_make_runtime(top_block)
def run(self):
- self._r.run()
+ runtime_run_unlocked(self._r)
+
+ def start(self):
+ runtime_start_unlocked(self._r)
+
+ def stop(self):
+ runtime_stop_unlocked(self._r)
+
+ def wait(self):
+ runtime_wait_unlocked(self._r)
pass
def test_001_run(self):
- hblock = gr.hier_block2("test_block",
+ hblock = gr.hier_block2("test_block",
gr.io_signature(0,0,0),
gr.io_signature(0,0,0))
- runtime = gr.runtime(hblock)
- runtime.run()
+ runtime = gr.runtime(hblock)
+ runtime.run()
def test_002_run_twice(self):
- hblock = gr.hier_block2("test_block",
+ hblock = gr.hier_block2("test_block",
gr.io_signature(0,0,0),
gr.io_signature(0,0,0))
- runtime = gr.runtime(hblock)
- runtime.run()
- self.assertRaises(RuntimeError, lambda: runtime.run())
+ runtime = gr.runtime(hblock)
+ runtime.run()
+ self.assertRaises(RuntimeError, lambda: runtime.run())
if __name__ == "__main__":
gr_unittest.main()