Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
733 views
in Technique[技术] by (71.8m points)

gnuradio - Stop GNU Radio Python block from blocking

I am creating a basic Python block in GNU Radio Companion which sends a specified number of PDU messages at a desired rate. I will use this block to test a flowgraph I am building.

The block works well, but blocks/hangs until it has finished sending all messages. I would like to implement some code to cause the block to stop when the GRC flow graph is stopped.

I have implemented some code to stop the sending thread when signalled to do so, which works well (I tested by manually setting self.stop_thread to True. However I cannot figure out out to send this signal using GRC / GR.

The structure of my code is shown below. How do I trigger the stop() function in GRC / GR?

class SendMessages(threading.Thread):

    def __init__(self, num_messages, send_msg_cb, msg_per_second, stop_thread):
        # Inherit all the parameters passed to __init__
        super().__init__()
        ...
        self.stop_thread = stop_thread

    def run(self):
        print(f'Sending {self.num_messages} messages')
        
        if self.stop_thread():
            print(f'Stopping thread')
            break
        ...

class blk(gr.basic_block): 
    def __init__(......):
        ...
        # start SendMessages thread and send self.stop_thread to the new thread with a value of False

    # This function never gets called :(
    def stop(self):
        print(f'Stopping block')
        self.stop_thread = True
        return True
question from:https://stackoverflow.com/questions/65952623/stop-gnu-radio-python-block-from-blocking

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...