# How do I kill a task / coroutine in Julia?

**URL:** https://discourse.julialang.org/t/how-do-i-kill-a-task-coroutine-in-julia/26683
**Category:** General Usage
**Tags:** parallel
**Created:** [July 23, 2019, 1:16pm UTC](https://discourse.julialang.org/t/how-do-i-kill-a-task-coroutine-in-julia/26683 "2019-07-23T13:16:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![AtsushiSakai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atsushisakai/32/6559_2.png) [@AtsushiSakai](https://discourse.julialang.org/u/AtsushiSakai)
#### Post date: [July 23, 2019, 1:16pm UTC](https://discourse.julialang.org/t/how-do-i-kill-a-task-coroutine-in-julia/26683/1 "2019-07-23T13:16:57Z")

</div>

I have a totally same question as this:  
How do I kill a task / coroutine in Julia? - Stack Overflow [How do I kill a task / coroutine in Julia? - Stack Overflow](https://stackoverflow.com/questions/27209663/how-do-i-kill-a-task-coroutine-in-julia)

I tried the same way to kill the task of the answer like:

```julia
t = @async run(`server_run.sh`) # start a task
...
Base.throwto(t, InterruptException()) # stop the task

```

The task might be a external program written in another language.

But this didn’t work in Julia 1.1. (It was just stopping the processing at the line.)

Does anyone know a solution for it?

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [July 23, 2019, 6:00pm UTC](https://discourse.julialang.org/t/how-do-i-kill-a-task-coroutine-in-julia/26683/2 "2019-07-23T18:00:09Z")

</div>

What do you want to happen that you’re not seeing happen? If you’re missing the garbage collection of things the task allocated, you can just assign `t = nothing` and it’ll then eventually collect all that trash.

---

<div class="post-metadata">

### Author: ![AtsushiSakai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atsushisakai/32/6559_2.png) [@AtsushiSakai](https://discourse.julialang.org/u/AtsushiSakai)
#### Post date: [July 24, 2019, 12:30pm UTC](https://discourse.julialang.org/t/how-do-i-kill-a-task-coroutine-in-julia/26683/3 "2019-07-24T12:30:42Z")

</div>

Hi. @mbauman I would like to kill the task which is executed by async.  
But when I do nothing, the task is still running after finishing the julia script.

---

<div class="post-metadata">

### Author: ![paalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paalon/32/5784_2.png) [@paalon](https://discourse.julialang.org/u/paalon)
#### Post date: [March 24, 2020, 8:10pm UTC](https://discourse.julialang.org/t/how-do-i-kill-a-task-coroutine-in-julia/26683/4 "2020-03-24T20:10:45Z")

</div>

@AtsushiSakai `run` make a **process**.

```julia
julia> process = run(`sleep 10`, wait=false)
Process(`sleep 10`, ProcessRunning)

```

You can kill a process by `kill`.

```julia
process = run(`sleep 10`, wait=false)
process_running(process) # true
kill(process)
process_running(process) # false

```
