# Precise interrupts in GNURADIO?

**URL:** <https://www.ruby-forum.com/t/precise-interrupts-in-gnuradio/234146>\
**Category:** GNU Radio\
**Created:** [February 9, 2015, 11:13pm UTC](https://www.ruby-forum.com/t/precise-interrupts-in-gnuradio/234146 "2015-02-09T23:13:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [February 9, 2015, 11:13pm UTC](https://www.ruby-forum.com/t/precise-interrupts-in-gnuradio/234146/1 "2015-02-09T23:13:40Z")

</div>

Dear all,  
In my application, I want to implement the following feature:  
1. If I decode 50 packages, then stop the flowgraph immediately  
2. otherwise, if after 30 seconds, I cannot receive more than 50  
packages, then stop the flowgraph. So I could prevent the flowgraph from  
locking forever.

```
  For the first part, I add a state machine inside the decoder. When

```

there are 50 packages decoded correctly, I would output a high level ‘1’  
on  
the output. Otherwise I output low level 0. I connect this output port,  
with a probe. In python, I wrote  
-------------------------------------------------------------  
def \_probe\_peak\_package\_number():  
while True:  
val = round(self.probe\_package\_number.level())  
if (val == 1):  
print “package number reach threshold %d!”  
%self.threshold  
self.stop()  
break  
\_probe\_package\_number\_thread =  
threading.Thread(target=\_probe\_peak\_package\_number)  
\_probe\_package\_number\_thread.daemon = True  
\_probe\_package\_number\_thread.start()  
-------------------------------------------------------------  
which starts a thread, listening to the probe. Whenever it observes a  
high  
level ‘1’, it would STOP the flowgraph immediately.

For the second part, I am using the Timer in the package threading.  
-------------------------------------------------------------  
#def \_shut\_down\_flow\_graph():  
#print “Passing %d seconds, going to kill the process!”  
%self.timing  
#self.stop()

```
    #_timer_thread=Timer(self.timing,_shut_down_flow_graph)
    #_timer_thread.start()
 -------------------------------------------------------------

```

But, what I observe is that:

1. If I set the threshold to 10 packages, I have to wait until about 100  
packages being decoded correctly. Sometimes I have to wait for about 500  
packages. The threading is not very stable, even there is an high-level  
output at the probe, it does not ‘see’ it immediately.

2. The alarm would prevent my flowgraph from exiting. Namely, when there  
are more than 50 packages, the flowgraph would not be stopped, until 30  
seconds passed. But I have a self.stop() in the snippet.

%self.threshold  
self.stop()  
break

Why it does not terminate the python program immediately?

Or, is there any suggestions on implementing precise interrupt in  
GNURADIO?

Thanks.

---

<div class="post-metadata">

**Author:** ![chenchen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c77e96/32.png) [@chenchen](https://www.ruby-forum.com/u/chenchen)\
**Post date:** [February 10, 2015, 4:07pm UTC](https://www.ruby-forum.com/t/precise-interrupts-in-gnuradio/234146/2 "2015-02-10T16:07:21Z")

</div>

Precise timings like this are difficult to do with GNU Radio, which is  
optimized for maximum throughput.

However, I think you can do things easier than you’re doing.  
First of all, you can stop the flowgraph from within blocks by returning  
WORK\_DONE from your work function. You can also return WORK\_DONE after a  
timeout, but that may have some unintended effects, or maybe your work  
function isn’t being called after the timeout.

However, you don’t necessarily need the probe.

On 02/09/2015 11:11 PM, Chen C. wrote:

> But, what I observe is that:
> 
> 1. If I set the threshold to 10 packages, I have to wait until about 100  
> packages being decoded correctly. Sometimes I have to wait for about 500  
> packages. The threading is not very stable, even there is an high-level  
> output at the probe, it does not ‘see’ it immediately.

You have little control over how data is processed, and it might happen  
that GNU Radio pushes very large chunks of data through the blocks in  
order to maximize throughput (thereby increasing latency).

> Why it does not terminate the python program immediately?  
> I don’t fully understand what you’re trying to do here.

M
