summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-core/src/lib/runtime/gr_runtime.i36
-rw-r--r--gnuradio-core/src/python/gnuradio/gr/hier_block2.py15
-rwxr-xr-xgnuradio-core/src/python/gnuradio/gr/qa_runtime.py14
3 files changed, 56 insertions, 9 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.i b/gnuradio-core/src/lib/runtime/gr_runtime.i
index 2933c7187..3a8b7e0b6 100644
--- a/gnuradio-core/src/lib/runtime/gr_runtime.i
+++ b/gnuradio-core/src/lib/runtime/gr_runtime.i
@@ -37,3 +37,39 @@ public:
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();
+}
+
+%}
diff --git a/gnuradio-core/src/python/gnuradio/gr/hier_block2.py b/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
index cd185d168..5877401b5 100644
--- a/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
+++ b/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
@@ -19,7 +19,9 @@
# 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.
@@ -47,4 +49,13 @@ class runtime(object):
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)
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_runtime.py b/gnuradio-core/src/python/gnuradio/gr/qa_runtime.py
index 1951afa8e..ce0bdde21 100755
--- a/gnuradio-core/src/python/gnuradio/gr/qa_runtime.py
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_runtime.py
@@ -11,19 +11,19 @@ class test_runtime(gr_unittest.TestCase):
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()