# Why sleep() throws EOFError?

**URL:** https://discourse.julialang.org/t/why-sleep-throws-eoferror/46106
**Category:** General Usage
**Created:** [September 5, 2020, 2:40pm UTC](https://discourse.julialang.org/t/why-sleep-throws-eoferror/46106 "2020-09-05T14:40:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![tisztamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tisztamo/32/16200_2.png) [@tisztamo](https://discourse.julialang.org/u/tisztamo)
#### Post date: [September 5, 2020, 2:40pm UTC](https://discourse.julialang.org/t/why-sleep-throws-eoferror/46106/1 "2020-09-05T14:40:14Z")

</div>

I got this, but cannot reproduce it for now:

```julia
┌ Error: xxxx
│ exception =
│ EOFError: read end of file
│ Stacktrace:
│ [1] wait at ./asyncevent.jl:128 [inlined]
│ [2] sleep at ./asyncevent.jl:213 [inlined]
...

```

I see that `wait(::Timer)` ([source](https://github.com/JuliaLang/julia/blob/697e782ab86bfcdd7fd15550241fe162c51d9f98/base/asyncevent.jl#L128)) throws this when `_trywait(::Timer)` returns `false`. But the cause is not clear.

Is this a real error (maybe in another task) or should I just catch and ignore it?

Thanks in advance!

---

<div class="post-metadata">

### Author: ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)
#### Post date: [November 23, 2022, 12:31pm UTC](https://discourse.julialang.org/t/why-sleep-throws-eoferror/46106/2 "2022-11-23T12:31:58Z")

</div>

Got an `EOFError` in a task from using `sleep(::Float64)`. When and why does that happen?

```julia
function _trywait(t::Union{Timer, AsyncCondition})
    set = t.set
    if set
        # full barrier now for AsyncCondition
        t isa Timer || Core.Intrinsics.atomic_fence(:acquire_release)
    else
        t.isopen || return false
        t.handle == C_NULL && return false
        iolock_begin()
        set = t.set
        if !set
            preserve_handle(t)
            lock(t.cond)
            try
                set = t.set
                if !set && t.isopen && t.handle != C_NULL
                    iolock_end()
                    set = wait(t.cond)
                    unlock(t.cond)
                    iolock_begin()
                    lock(t.cond)
                end
            finally
                unlock(t.cond)
                unpreserve_handle(t)
            end
        end
        iolock_end()
    end
    @atomic :monotonic t.set = false
    return set
end

function wait(t::Union{Timer, AsyncCondition})
    _trywait(t) || throw(EOFError())
    nothing
end

```

That’s the code from [julia/asyncevent.jl at v1.8.3 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/blob/v1.8.3/base/asyncevent.jl)

On Windows 8 with Julia 1.8.3
