# Base.throwto() blocking perpetually

**URL:** <https://discourse.julialang.org/t/base-throwto-blocking-perpetually/108237>\
**Category:** General Usage\
**Tags:** question, async\
**Created:** [January 1, 2024, 9:54pm UTC](https://discourse.julialang.org/t/base-throwto-blocking-perpetually/108237 "2024-01-01T21:54:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoO0oss](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@JoO0oss](https://discourse.julialang.org/u/JoO0oss)\
**Post date:** [January 1, 2024, 9:54pm UTC](https://discourse.julialang.org/t/base-throwto-blocking-perpetually/108237/1 "2024-01-01T21:54:31Z")

</div>

I recently found that `throwto()` never returns, it just hangs (see [this GitHub issue](https://github.com/JuliaLang/julia/issues/25353)) and constructed a little demo:

```julia
task = @async begin 
    while true
        print("-")
    end
end

sleep(0.003)
println("Throwing...")
Base.throwto(task, InterruptException())
println("Thrown.")

```

Perhaps this is better at home in New To Julia, but this has left me both confused and intrigued.

1. _Why?_ Was there a conscious design choice gone into that behaviour?
2. In the case where I may have any number of tasks where instead of `println("-")` it is a blocking call that takes an unknown (potentially infinite) amount of time (eg `readbytes!(mysocket, mylist, 4)`), how can I stop a task in middle of a blocking call from outside the task?

---

<div class="post-metadata">

**Author:** ![JoO0oss](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@JoO0oss](https://discourse.julialang.org/u/JoO0oss)\
**Post date:** [January 1, 2024, 10:00pm UTC](https://discourse.julialang.org/t/base-throwto-blocking-perpetually/108237/2 "2024-01-01T22:00:44Z")

</div>

Apparently the answer to the second question is quite easy, use `schedule(task, InterruptException(), error=true)` instead of `Base.throwto(task, InterruptException())`  
(See the very bottom of [this page](https://discourse.julialang.org/t/task-termination/25231/4).)

Although I am still curious as to why the infinitely hanging call, if that is used a non-limited number of times within a program would that eventually clog up memory with records of tasks/threads that have `throwto()` blocking them?
