# Message passing: strobe or \_post?

**URL:** <https://www.ruby-forum.com/t/message-passing-strobe-or-post/242549>\
**Category:** GNU Radio\
**Created:** [July 2, 2015, 4:56am UTC](https://www.ruby-forum.com/t/message-passing-strobe-or-post/242549 "2015-07-02T04:56:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [July 2, 2015, 4:56am UTC](https://www.ruby-forum.com/t/message-passing-strobe-or-post/242549/1 "2015-07-02T04:56:58Z")

</div>

I am testing the capability of posting messages to Python blocks via  
Python. I have included below a simple example in which the Python  
block just prints out the message received. In one case, I send  
messages to this block via the builtin gnuradio.blocks.message\_strobe  
block. In the other case I try to call \_post on the block directly from  
Python. The former case works, but not the latter. I’ve tried to delve  
into the code, but so far have not found an answer. Any advice would be  
appreciated.

Jared.

Ubuntu 14.04  
Python 2.7.6  
GR 3.7.8

#!/usr/bin/env python  
##################################################

# Message passing example

# Jared D.

# 

##################################################

from gnuradio import gr, blocks  
import pmt  
import json  
import time

class message\_print(gr.sync\_block):  
def **init** (self):  
gr.sync\_block. **init** (self, “message\_print”, None, None)

```
    self.msg_port = mport = "in_port"
    self.message_port_register_in(pmt.intern(mport))
    self.set_msg_handler(pmt.intern(mport), self.print_msg)

def print_msg(self, msg):
    print "RECEIVED: ",
    print json.dumps(pmt.to_python(msg))

```

def main(\*args):  
if “strobe” in args:  
main\_strobe()  
else:  
main\_no\_strobe()

def main\_no\_strobe():  
tb = gr.top\_block()  
msg\_printer = message\_print()  
tb.connect(msg\_printer)  
tb.start()  
for n in range(10):  
time.sleep(0.1)  
msg\_printer.to\_basic\_block().\_post(pmt.intern(msg\_printer.msg\_port),  
pmt.to\_pmt({‘NUM’: n}))  
tb.stop()  
tb.wait()

def main\_strobe():  
tb = gr.top\_block()  
msg\_printer = message\_print()  
msg\_strobe = blocks.message\_strobe(pmt.to\_pmt({‘NUM’: -1}), 100)  
tb.msg\_connect(msg\_strobe, “strobe”, msg\_printer,  
msg\_printer.msg\_port)  
tb.start()  
time.sleep(1)  
tb.stop()  
tb.wait()

if **name** == ‘ **main** ’:  
import sys  
sys.exit(main(\*sys.argv[1:]))
