# File source and seek()

**URL:** <https://www.ruby-forum.com/t/file-source-and-seek/239688>\
**Category:** GNU Radio\
**Created:** [March 10, 2014, 6:39pm UTC](https://www.ruby-forum.com/t/file-source-and-seek/239688 "2014-03-10T18:39:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [March 10, 2014, 6:39pm UTC](https://www.ruby-forum.com/t/file-source-and-seek/239688/1 "2014-03-10T18:39:17Z")

</div>

Hello,

I am having some trouble getting the seek() function in the file source  
to  
work.

My program has a non-repeating file source, and a GUI button with the  
callback function set\_button(). In the callback I have written the below  
code, which should reset the file source to the beginning of the file:

self.blocks\_file\_source\_0.seek(0,0)

When I press the button before the file source has streamed to the end,  
the  
seek() works fine and resets the file source to the beginning. When I  
press  
the button after the file source has streamed to the end and stopped,  
the  
seek() does not work and nothing happens in the code. I suspect this has  
something to do with the scheduler thinking this block is done and  
ignoring  
it or deleting it or something, but I have been unable to get it working  
the way I want it to.

Any ideas what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![trracer\_dangly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/43a26b/32.png) [@trracer\_dangly](https://www.ruby-forum.com/u/trracer_dangly)\
**Post date:** [March 10, 2014, 10:38pm UTC](https://www.ruby-forum.com/t/file-source-and-seek/239688/2 "2014-03-10T22:38:14Z")

</div>

On 03/10/2014 06:38 PM, trracer dangly wrote:

> When I press the button before the file source has streamed to the end,  
> the seek() works fine and resets the file source to the beginning. When  
> I press the button after the file source has streamed to the end and  
> stopped, the seek() does not work and nothing happens in the code. I  
> suspect this has something to do with the scheduler thinking this block  
> is done and ignoring it or deleting it or something, but I have been  
> unable to get it working the way I want it to.

You’re on the right track: In a non-repeating file source, the block  
will return -1 after the file was read, which triggers a shutdown of the  
FG. So, what you really want is to restart the flow graph.

Perhaps you need to write your own block which acts on your inputs.

M
