# Stop() the flow graph

**URL:** <https://www.ruby-forum.com/t/stop-the-flow-graph/233040>\
**Category:** GNU Radio\
**Created:** [November 13, 2014, 8:30am UTC](https://www.ruby-forum.com/t/stop-the-flow-graph/233040 "2014-11-13T08:30:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [November 13, 2014, 8:30am UTC](https://www.ruby-forum.com/t/stop-the-flow-graph/233040/1 "2014-11-13T08:30:04Z")

</div>

Hi All,

I am looking for a solution that start() the flow graph for a definite  
period of time (in seconds) and after that it stop() it automatically.  
For  
example

# let suppose initial value of time is 14 seconds; it means that the

flowgraph defined in tb1 should need to executed during that time; and  
when  
the time reaches zero it must be stop.

while 1:  
if (time!=0):  
tb1.run()  
time = int(time) - int(1)  
elif (time==0):  
tb1.stop()

I tried this; but once the flow graph started; then it never comes to  
the  
elif condition. How can I stop() the flowgraph in this condition.  
Waiting  
for reply.

Regards,

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 13, 2014, 10:17am UTC](https://www.ruby-forum.com/t/stop-the-flow-graph/233040/2 "2014-11-13T10:17:30Z")

</div>

tb1.start()  
time.sleep(14)  
tb1.stop()  
tb1.wait()

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 13, 2014, 10:54am UTC](https://www.ruby-forum.com/t/stop-the-flow-graph/233040/3 "2014-11-13T10:54:34Z")

</div>

Thanks Sylvain for your reply; but if I introduced sleep(14) then during  
that time it won’t perform the tasks in tb1 as well.

On Thu, Nov 13, 2014 at 3:28 PM, Syed Aqeel R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 13, 2014, 12:52pm UTC](https://www.ruby-forum.com/t/stop-the-flow-graph/233040/4 "2014-11-13T12:52:28Z")

</div>

> I can’t use sleep() here; because there’re other threads as well in the  
> program which need to be executed as well. Sleep() stop the execution of  
> program; which is not a solution.

No it doesn’t. It pauses the execution of the _THREAD_ … other  
threads (both those created by gnuradio to actually run the flow graph  
and whatever other thread you have in your application) will keep  
running.

Besides you’re missing the point … the main thing to notice in my  
original reply is run() vs start(). One is blocking, the other isn’t.

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 13, 2014, 11:34am UTC](https://www.ruby-forum.com/t/stop-the-flow-graph/233040/5 "2014-11-13T11:34:04Z")

</div>

I can’t use sleep() here; because there’re other threads as well in the  
program which need to be executed as well. Sleep() stop the execution of  
program; which is not a solution. Thanks.

On Thu, Nov 13, 2014 at 5:53 PM, Syed Aqeel R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 15, 2014, 8:57am UTC](https://www.ruby-forum.com/t/stop-the-flow-graph/233040/6 "2014-11-15T08:57:51Z")

</div>

Hi,

Currently, I am using a single usrp as a transmitter. The program is  
changing the transmission frequency with respect to (external) switching  
time. In order to change the frequency in usrp box; I set the following  
programming conditions.

while 1:  
if ((time!=0) and ((ch1=1) or (ch2==1))):  
tb1.start()  
time = int(time) - int(1)  
sleep(external time which provide the active channel time of  
channel 1 and channel 2)  
elif (time==0):  
tb1.stop()

But (I think) due to this frequent start() and stop() activities; after  
maximum of 15 minutes time I have received the following error.

/Traceback (most recent call last):  
File “source\_test.py”, line 121, in   
tb1 = gmsk\_tx()  
File “source\_test.py”, line 88, in **init**  
self.blocks\_udp\_source\_0 = blocks.udp\_source(gr.sizeof\_char\*1,  
“127.0.0.1”,  
1234, 1472, True)  
File  
“/usr/local/lib/python2.7/dist-packages/gnuradio/blocks/blocks\_swig5.py”,  
line 1969, in make  
return \_blocks\_swig5.udp\_source\_make(\*args, \*\*kwargs)  
RuntimeError: boost::thread\_resource\_error: Resource temporarily  
unavailable

I want the program to be run continuously. Kindly propose some solution.

Regards,  
Syed Aqeel R.

On Thu, Nov 13, 2014 at 6:32 PM, Syed Aqeel R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 15, 2014, 1:47pm UTC](https://www.ruby-forum.com/t/stop-the-flow-graph/233040/7 "2014-11-15T13:47:42Z")

</div>

Try putting wait() after stop() to make sure the resources are teared  
down.
