# Task not runnable error

**URL:** https://discourse.julialang.org/t/task-not-runnable-error/73506
**Category:** General Usage
**Tags:** task
**Created:** [December 22, 2021, 6:50pm UTC](https://discourse.julialang.org/t/task-not-runnable-error/73506 "2021-12-22T18:50:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)
#### Post date: [December 22, 2021, 6:50pm UTC](https://discourse.julialang.org/t/task-not-runnable-error/73506/1 "2021-12-22T18:50:32Z")

</div>

Hi folks, I have a task that says it’s runnable, but I get a task not runnable error:

```julia
julia> task = @task readline(stdin)
Task (runnable) @0x000000010f798010

julia> yield(task)

julia> task
Task (runnable) @0x000000010f798010

julia> yield(task)
ERROR: yield: Task not runnable
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] yield (repeats 2 times)
   @ ./task.jl:737 [inlined]
 [3] top-level scope
   @ REPL[4]:1

julia> task
Task (runnable) @0x000000010f798010

```

What is going on here?

---

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [December 22, 2021, 9:48pm UTC](https://discourse.julialang.org/t/task-not-runnable-error/73506/2 "2021-12-22T21:48:18Z")

</div>

I’d say the printing of the task is misleading here. `(runnable)` does not mean “the user can schedule it.”

Also, I think it’s very tricky to use `yield` for a task that is already started. In particular, the code in the OP is not correct. If you want to know when `yield` can be called on the task that is already started, have a look at [https://github.com/JuliaLang/julia/pull/41270](https://github.com/JuliaLang/julia/pull/41270) which discusses when `schedule` can be used for the task that is already started. Using `yield` is even more strict since you have to know that the context switch has been completed. I think this requires knowing the worker thread that executed the said task and then that the worker thread is now executing another task.

In short: I don’t think you’d want to do this.

---

<div class="post-metadata">

### Author: ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)
#### Post date: [December 22, 2021, 11:04pm UTC](https://discourse.julialang.org/t/task-not-runnable-error/73506/3 "2021-12-22T23:04:37Z")

</div>

I think the zero argument `yield()` proved the best solution for my use case.

---

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [December 23, 2021, 1:38am UTC](https://discourse.julialang.org/t/task-not-runnable-error/73506/4 "2021-12-23T01:38:37Z")

</div>

Yes, zero-arg `yield()` is a good API for telling the scheduler to try other tasks.
