# How to kill thread?

**URL:** <https://discourse.julialang.org/t/how-to-kill-thread/34236>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [February 6, 2020, 5:25am UTC](https://discourse.julialang.org/t/how-to-kill-thread/34236 "2020-02-06T05:25:10Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [February 6, 2020, 6:22am UTC](https://discourse.julialang.org/t/how-to-kill-thread/34236/5 "2020-02-06T06:22:58Z")

</div>

You need to get the task handle to kill it, like that:

```julia
using .Threads

function hanging()
    println("I'm hanging on thread:", threadid())
    while true
        sleep(1)
    end
end

julia> hang = Threads.@spawn hanging();

julia> I'm hanging on thread:2

julia> hang
Task (runnable) @0x000000010f5698d0

julia> schedule(hang, ErrorException("stop"), error=true)
Task (failed) @0x000000010f5698d0
stop
try_yieldto(::typeof(Base.ensure_rescheduled), ::Base.RefValue{Task}) at ./task.jl:611
....

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-kill-thread/34236)._
