Callback from message sink is stopped

Hi All,

I am a begginer in GNU Radio. I have sent my first question once,maybe 3
or
4 weeks ago, but nobody answer it. It is OK, since I solved the
problem.
But this time , I am really stuck with the problem for 2 weeks. could
anyone answer my problem? please help me. I hope there is a nice person
who
can answer my problem.

I have a problem with the combination of message_source and
message_sink. my
code is written below.
The program is executed without any error. But what i am confused is
sometimes it stopped even though the number of pktno isn’t 1499 yet. I
am
hoping to get all the packet to printed in stdout.
please help me why it happen?

Best Regards,
Tim

from gnuradio import gr, usrp2, blks2, packet_utils
import gnuradio.gr.gr_threading as _threading
import threading
import struct

class my_top_block(gr.top_block):
def init(self,callback=None,msq_limit = 2):
gr.top_block.init(self)
self.packet_sink = gr.msg_queue()
self.src = gr.message_source(gr.sizeof_char, msq_limit)
self.sink = gr.message_sink(gr.sizeof_char,self.packet_sink,False)
self.connect(self.src,self.sink)

def main():
def send(payload=’’,eof=False) :

    if eof== True :
        tb.src.msgq().insert_tail(gr.message(1))
    else :

print ‘send payload’

        tb.src.msgq().insert_tail(gr.message_from_string(payload))



def receive(payload) :
    print payload



tb = my_top_block()
nbytes = 1e6
tb.start()
n=0
pktno=0
pkt_size=30
tb.watcher = simple_thread(tb.packet_sink,receive)

while n < nbytes:

while pktno <1500:

send(struct.pack(’!H’, pktno & 0xffff) + (pkt_size - 2)

chr(pktno & 0xff))
payload = ‘pktno = %d \n’%pktno

       send(payload)
            n += pkt_size
           pktno += 1

 send(eof=True)

tb.wait()

class simple_thread(_threading.Thread):
def init(self, msgq1,receive):
_threading.Thread.init(self)
self.setDaemon(1)
self.msgq1 = msgq1
self.receive = receive
self.keep_running = True
self.start()

def run(self):
    while self.keep_running:

if self.msgq1.count >= 0 :

        print self.msgq1.empty_p()
        payload = self.msgq1.delete_head().to_string()

            if self.receive :
            self.receive(payload)

if name == “main”:
main()