1

I am using GNU Radio's logging functionality in some custom python blocks I've built for a flowgraph. Among other things, the logging methods are useful for recording the (rough) start time of the flowgraph to a log file. I would also like to record the end time of the flowgraph (i.e., the rough time I kill the flowgraph in companion) in a log message written to the log file. To be clear, I'm looking for a solution that will work when I run the flowgraph from GNU Radio Companion. Is there an easy way to do this?

rhz
  • 960
  • 14
  • 29

1 Answers1

1

In GNU Radio blocks, you can overload the stop method to do exactly that, execute code at flow graph stop time.

Generally, the "stop" button in GRC is a rather hardcore thing; if you instead have a finishing condition in your flowgraph itself (e.g. closing of the window if you're using Qt GUI, or finishing of any block), this could be approached from that logical "I should be done" point of view, rather than "someone else tries to kill me".

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • I've seen the suggestion to overload the stop method to do this, but how would that work in python for a flowgraph I'm running from GRC? I do have many custom hierarchical blocks in python in this flowgraph. What change would I make to the python of one of these blocks to detect that it's finishing so that I could write a final message to the log file before everything shuts down? – rhz Jan 26 '20 at 19:51
  • hm, don't know from the top of my head whether that stop method also exists in hier blocks – I meant "proper" gr::block – Marcus Müller Jan 26 '20 at 19:54
  • Well, my hier blocks contain gr.blocks. Even in that case, could you give an example of how the code would look ? The only kind of overloading I'm familiar with in python is that of having argument lists of varying length in custom functions/methods. – rhz Jan 26 '20 at 20:52
  • you'd need to overload the stop of a gr.block subclass, not have a hier block that contains instances of gr.block subclasses. – Marcus Müller Jan 26 '20 at 20:59
  • Sorry, my python skills are weak. For example, my flowgraph contains a throttle. Are you saying that I should create a new class derived from gr.block that I can use for a new throttle that has something special happen upon stop? If so, what would the python code look like for this? – rhz Jan 26 '20 at 21:12