# How to tell if a Task is blocked?

**URL:** <https://discourse.julialang.org/t/how-to-tell-if-a-task-is-blocked/32392>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 17, 2019, 4:56pm UTC](https://discourse.julialang.org/t/how-to-tell-if-a-task-is-blocked/32392 "2019-12-17T16:56:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hwjsnc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hwjsnc/32/15178_2.png) [@hwjsnc](https://discourse.julialang.org/u/hwjsnc)\
**Post date:** [December 17, 2019, 4:56pm UTC](https://discourse.julialang.org/t/how-to-tell-if-a-task-is-blocked/32392/1 "2019-12-17T16:56:15Z")

</div>

I have a `Task` executed with `@async`. This task writes to a `Channel` multiple times (it is not known exactly how often), then reads from another `Channel` once. This should repeat until some condition is met. The main thread should wait for all output of the task, then write to it once. This should repeat until the task is finished. What is sent to the task depends on what the task sent before.

Here is a contrived example:

```julia
function f(input, output)
  while true
    put!(output, rand(-1:1))
    if rand(1:10) == 1
      take!(input) == 0 && return
    end
  end
end

input = Channel{Int}(Inf)
output = Channel{Int}(Inf)

task = @async f(input, output)

while !istaskdone(task)
  s = 0
  sleep(0.01) # FIXME: wait until task is trying to take! from input
  while isready(output)
    s += take!(output)
  end
  println(s)
  put!(input, s)
  yield()
end

```

In this situation, how can I reliably tell if task is blocked or is still sending input? I’d be happy about any hints or suggestions.

(Note: I asked [this question](https://www.reddit.com/r/Julia/comments/ea2pay/how_to_tell_if_a_task_is_blocked/) a few days ago on on reddit and didn’t get a solution. Reddit user u/wherrera10 suggested using an unbuffered Channel and `isready`, but this only works to tell if a task is blocked trying to `put!` to an unbuffered `Channel`)

---

<div class="post-metadata">

**Author:** ![hwjsnc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hwjsnc/32/15178_2.png) [@hwjsnc](https://discourse.julialang.org/u/hwjsnc)\
**Post date:** [December 28, 2019, 1:12pm UTC](https://discourse.julialang.org/t/how-to-tell-if-a-task-is-blocked/32392/2 "2019-12-28T13:12:47Z")

</div>

bump
