# Get information on state of IOStream

**URL:** <https://discourse.julialang.org/t/get-information-on-state-of-iostream/66910>\
**Category:** General Usage\
**Tags:** io\
**Created:** [August 24, 2021, 12:52pm UTC](https://discourse.julialang.org/t/get-information-on-state-of-iostream/66910 "2021-08-24T12:52:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DorianT](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doriant/32/24897_2.png) [@DorianT](https://discourse.julialang.org/u/DorianT)\
**Post date:** [August 24, 2021, 12:52pm UTC](https://discourse.julialang.org/t/get-information-on-state-of-iostream/66910/1 "2021-08-24T12:52:39Z")

</div>

Hey everyone! I have a function `makebatch!(::IOStream, kwargs...)` that creates one batch of data to feed to a model (from a file). For this the function takes an IOStream and reads as many lines as it needs to fill the batch (e.g. after every `readline` from the IOStream it checks if it has to read another line, so the number of lines read per batch is arbitrary).

To train the model I want to do multiple epochs of this procedure (it may be better to store the data after the first read, but it’s pretty big and I want to tackle this problem later on). Ideally I would want something like this:

```julia
for epoch in 1:10
    io = open("data.txt")
    while isopen(io)
        batch = makebatch!(io)
        train!(batch)
    end
end

```

Is there a correct condition I can use here (because `while isopen(io)` does not work. Basically I want to tell my code to keep making batches and train the model with them until the IOStream is exhausted, but I could not find a function to track the state of the IOStream since it does not seem to get closed automatically when it reached its end.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 25, 2021, 6:00pm UTC](https://discourse.julialang.org/t/get-information-on-state-of-iostream/66910/2 "2021-08-25T18:00:50Z")

</div>

Maybe you could use `while !eof(io)`?  
See one example [here](https://discourse.julialang.org/t/reading-complex-text-files-with-vectors/66954/6).

---

<div class="post-metadata">

**Author:** ![DorianT](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doriant/32/24897_2.png) [@DorianT](https://discourse.julialang.org/u/DorianT)\
**Post date:** [August 26, 2021, 6:46pm UTC](https://discourse.julialang.org/t/get-information-on-state-of-iostream/66910/3 "2021-08-26T18:46:48Z")

</div>

Thank you very much, that was exactly what I was looking for! Guess I should have more carefully checked `methodswith(IOStream)`!
