I'm trying to write a python unit test for a GNU Radio messaging block that's conceptually very similar to message_debug
. I noticed that _post
ing a message to the block returns without error but has no effect. Here's message_debug
displaying the same behavior:
>>> msgdbg = blocks.message_debug()
>>> msgdbg.to_basic_block()._post(pmt.intern('print'), pmt.intern("test"))
>>> msgdbg.to_basic_block()._post(pmt.intern('store'), pmt.intern("test"))
>>> msgdbg.num_messages()
0
I'm having trouble understanding why this happens and what steps I need to take to write a unit test for a message accepting block.
_post
ing to a block which is not part of a running flowgraph including doesn't work.
This is because GNU Radio has a thread-based scheduler, where every block lives inside his own thread, that basically goes through an infinite loop of checking in- and output streams for space, calling general_work
as feasible, then checking whether the block has message handlers registered and and whether there are messages in the queue.
If you haven't started a flow graph, there's no thread and no loop running to check the queue.
Now, the fact that you can't use _post
even while running in a flow graph was actually a bit surprising to me at first, but then I came to the realization that only blocks that are actually somehow connected actually get their own thread.