# How to limit the size of buffer/queue for a block?

**URL:** <https://www.ruby-forum.com/t/how-to-limit-the-size-of-buffer-queue-for-a-block/239710>\
**Category:** GNU Radio\
**Created:** [March 11, 2014, 2:22pm UTC](https://www.ruby-forum.com/t/how-to-limit-the-size-of-buffer-queue-for-a-block/239710 "2014-03-11T14:22:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [March 11, 2014, 2:22pm UTC](https://www.ruby-forum.com/t/how-to-limit-the-size-of-buffer-queue-for-a-block/239710/1 "2014-03-11T14:22:09Z")

</div>

Hello

The flowgraph of my top\_block has test\_demo as one of the blocks. The  
work() function associated with it has only one print statement.  
When I execute the flowgraph, the statement keeps on printing the  
statement  
" I AM IN WORK" on the screen. Why does it happen?  
My flowgraph is :  
File source—\>stream to datagram—\>test\_demo----\>datagram to  
stream-----\>file sink

test\_demo.py is :

import timing  
import numpy  
import gras  
import Queue  
import thread  
from gnuradio import gr  
from gnuradio import digital  
from gnuradio import uhd  
import grextras

class test\_demo(gras.Block):

def **init** (self, threshold):  
gras.Block. **init** (self,name=“test\_demo”,  
in\_sig = [numpy.uint8,numpy.uint8,numpy.uint8],  
out\_sig = [numpy.uint8,numpy.uint8])  
self.input\_config(0).reserve\_items = 0  
self.input\_config(1).reserve\_items = 0  
self.output\_config(1).reserve\_items = 4096  
self.output\_config(0).reserve\_items = 4096  
self.threshold=threshold  
print “inside test\_demo”

def work(self,ins,outs):  
print “I AM IN WORK”

If it is due to the size of buffer/queue of the block then how can I  
limit  
it?  
I understand that work() keeps on executing till the block receives  
something at its input ports. I want work() to return the control to  
main  
flowgraph upon satisfying a user specified condition such as  
if (i=5):  
self.mark\_done()  
It should ignore all the pending packets of the buffer/queue.  
I want to start my flowgraph fresh after this process.

---

<div class="post-metadata">

**Author:** ![Sumedha\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b9bd4f/32.png) [@Sumedha\_G](https://www.ruby-forum.com/u/Sumedha_G)\
**Post date:** [March 11, 2014, 3:13pm UTC](https://www.ruby-forum.com/t/how-to-limit-the-size-of-buffer-queue-for-a-block/239710/2 "2014-03-11T15:13:22Z")

</div>

On 03/11/2014 02:20 PM, Sumedha G. wrote:

> test\_demo.py is :  
> Sumedha,

when posting Python code, make sure the indents get preserved (ideally,  
don’t send HTML emails).

M
