discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Python Script Stalls


From: Johnathan Corgan
Subject: Re: [Discuss-gnuradio] Python Script Stalls
Date: Wed, 11 Nov 2015 13:35:28 -0800

On Wed, Nov 11, 2015 at 10:59 AM, Richard Bell <address@hidden> wrote:
John, did you mean this four step process, otherwise stop before wait doesn't let anything happen:

tb.start()
tb.wait()
tb.stop()
tb.wait()

Like that? If so, why don't the auto-generated top_blocks have to do that?

​To clarify what is happening under the hood here, let me go through what these calls actually do.

tb.start() creates and runs a thread for each block in the flowgraph, and immediately returns to the foreground thread execution. One uses this form when one wants to continue to do other things in the application while the flowgraph is running in the background.  This is typically used with GUI applications that have their own event loop thread.

At the end of the application, one must call tb.stop(), which issues a cancel to each thread, and then tb.wait(), which joins each thread and ensures everything is cleaned up before continuing.

​Now, flowgraphs can either exit on their own, such when a finite data source is used, or a head() block is in place, or they run indefinitely.  In either case, if the flowgraph is started with tb.start(), it must eventually be followed with tb.stop() and tb.wait().

The alternative, which is more common in non-GUI scripts, is to use tb.run().  This will internally call start(), and then block either until the flowgraph to exits on its own, or a SIGINT (ctrl-c) arrives.  It then calls tb.stop() and tb.wait() internally, then returns.

Thus, the simpler tb.run() semantics let you create a flowgraph, let it run till exit, or break out of it with SIGINT.  When tb.run() returns, there is nothing else the user needs to do.  Hence, many command-line examples you see in GNU Radio use tb.run().  If they use the tb.start() method, which again, returns immediately to the foreground, they usually have a raw input call or something else that blocks until the user does something, then they call tb.stop() and tb.wait().

It sounds like what you are trying to do, if I understood correctly, is run a finite-length flowgraph over and over again.  For that, tb.run() should suffice.  If the flowgraph is not guaranteed to exit on its own, then you'll need to do tb.start(), block while you figure out whether conditions are proper for terminating the flowgraph, then do tb.stop() and tb.wait().

-- 
Johnathan Corgan
Corgan Labs - SDR Training and Development Services

reply via email to

[Prev in Thread] Current Thread [Next in Thread]