Daniel
Daniel

Reputation: 607

GNU Radio Block run code on program termination

I am writing a gnuradio sink block for custom SDR hardware. When the gnuradio program is closed, I need to make sure that the power amplifiers are disabled (as they draw quite a bit of power and produce a lot of heat). I tried doing this with a class destructor thinking it would be called upon program termination, however it was not. Does gnuradio provide a way to run cleanup upon program termination?

Upvotes: 2

Views: 853

Answers (2)

pianoJames
pianoJames

Reputation: 484

Example of overriding in Python: if you insert a Python block, add the stop method like so:


class blk(gr.sync_block):
    def __init__(self):
        # omitted...

    def work(self):
        # omitted...

    def stop(self):
        print "do stopping work here"
        return True

Notes:

  • I don't know what the return value is used for. (Answered in comments -- thanks!)
  • In my experimentation, it appears that stop does not run for blocks that lack inputs and outputs.

Upvotes: 1

Marcus Müller
Marcus Müller

Reputation: 36442

You could overload the stop method of the gr::block base class. It's meant for exactly that!

Upvotes: 2

Related Questions