# File Sink open/close question

**URL:** <https://www.ruby-forum.com/t/file-sink-open-close-question/229666>\
**Category:** GNU Radio\
**Created:** [January 22, 2013, 10:20am UTC](https://www.ruby-forum.com/t/file-sink-open-close-question/229666 "2013-01-22T10:20:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hanzzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b19c9b/32.png) [@hanzzz](https://www.ruby-forum.com/u/hanzzz)\
**Post date:** [January 22, 2013, 10:20am UTC](https://www.ruby-forum.com/t/file-sink-open-close-question/229666/1 "2013-01-22T10:20:10Z")

</div>

Hi!  
Im using a message queue to count data, while the data is sinked to a  
file.  
Then if the counter reaches X i want the old file to be closed and  
continue  
sinking in a new file. Then again if reaches X to switch to the old  
file. So  
my bottom part code looks like that:

tb = top\_block()  
tb.start()  
a=0

while 1:  
if tb.sink\_queue.count()\>X:  
tb.gr\_file\_sink\_0.close()  
tb.sink\_queue.flush()  
if a==0:  
tb.gr\_file\_sink\_0.open(“PLACE\_TO\_SAVE\two”)  
a=1  
else:  
tb.gr\_file\_sink\_0.open(“PLACE\_TO\_SAVE\one”)  
a=0

Right now, it simply closes the first file, but does not begin with the  
second one. Can anyone help me with that? Thanks in advance

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/File-Sink-open-close-question-tp39098.html](http://gnuradio.4.n7.nabble.com/File-Sink-open-close-question-tp39098.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![hanzzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b19c9b/32.png) [@hanzzz](https://www.ruby-forum.com/u/hanzzz)\
**Post date:** [January 22, 2013, 12:36pm UTC](https://www.ruby-forum.com/t/file-sink-open-close-question/229666/2 "2013-01-22T12:36:17Z")

</div>

Hans:

Where are you “resetting X”?

---

<div class="post-metadata">

**Author:** ![hanzzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b19c9b/32.png) [@hanzzz](https://www.ruby-forum.com/u/hanzzz)\
**Post date:** [January 22, 2013, 12:53pm UTC](https://www.ruby-forum.com/t/file-sink-open-close-question/229666/3 "2013-01-22T12:53:14Z")

</div>

I setted X some lines before as 1000. And the tb.sink\_queue.count() is  
resetted by tb.sink\_queue.flush() i thought.

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/File-Sink-open-close-question-tp39098p39101.html](http://gnuradio.4.n7.nabble.com/File-Sink-open-close-question-tp39098p39101.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![hanzzz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b19c9b/32.png) [@hanzzz](https://www.ruby-forum.com/u/hanzzz)\
**Post date:** [January 23, 2013, 4:27pm UTC](https://www.ruby-forum.com/t/file-sink-open-close-question/229666/4 "2013-01-23T16:27:49Z")

</div>

On Tue, Jan 22, 2013 at 4:18 AM, Hanz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Right now, it simply closes the first file, but does not begin with the  
> second one. Can anyone help me with that? Thanks in advance

Hanz,  
This shouldn’t make any difference, but the file\_sink’s ‘open’ function  
also closes any previously opened files. Try removing your call to  
‘close’  
and just rely on the open to close it, reopen the new file, and then  
when  
the work is called the next time, it will run ‘do\_update’ to set up the  
handles properly.

Also, you can try throwing in some debug prints to make sure both paths  
are  
actually being called properly.

Tom
