|
From: | Ed Coleman |
Subject: | Re: [Discuss-gnuradio] proper use of start(), stop(), and wait() to interact with program flow |
Date: | Wed, 29 Jun 2016 12:35:34 -0400 |
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.
[Prev in Thread] | Current Thread | [Next in Thread] |