[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Discuss-gnuradio] proper use of start(), stop(), and wait() to inte
From: |
Kevin Reid |
Subject: |
Re: [Discuss-gnuradio] proper use of start(), stop(), and wait() to interact with program flow |
Date: |
Wed, 29 Jun 2016 08:04:11 -0700 |
On Jun 29, 2016, at 07:50, Ed Coleman <address@hidden> wrote:
> if __name__ == '__main__':
> simpleTone().run()
>
> The code above works fine, however if I make the following substitution:
>
> if __name__ == '__main__':
> simpleTone().start()
> simpleTone().wait()
> #time.sleep(3)
> simpleTone().stop()
>
> The result is that the file runs, and ends after 3 seconds but no audio is
> produced.
Your problem is that you're constructing three unrelated top blocks: you have
three separate occurrences of "simpleTone()". Instead you need to create one
and continue to use it, like so:
tb = simpleTone()
tb.start()
...
tb.stop()
You have another problem, too, which you will find after fixing the first one.
.wait() means to wait for the flowgraph to finish all processing, and your
flowgraph has no elements within it to finish such as a Head block, so the
.stop() will never be reached.
Instead, you need to proceed like this:
tb = simpleTone()
tb.start()
# the flowgraph is now running independently
time.sleep(3)
tb.stop()
tb.wait()
The final .wait() is not actually necessary in this case -- what it does is
wait for the flowgraph to finish, which will happen shortly after .stop() is
called, but if you later wish to start the same top block again, you must have
called .wait() before you call .start(), so always having a matched set of
[start, stop, wait] or [start, wait, stop] is good practice.