# How to get backtrace of \`@async\` Task

**URL:** <https://discourse.julialang.org/t/how-to-get-backtrace-of-async-task/18170>\
**Category:** General Usage\
**Created:** [November 30, 2018, 3:56am UTC](https://discourse.julialang.org/t/how-to-get-backtrace-of-async-task/18170 "2018-11-30T03:56:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [November 30, 2018, 8:32am UTC](https://discourse.julialang.org/t/how-to-get-backtrace-of-async-task/18170/2 "2018-11-30T08:32:22Z")

</div>

You can either print the error yourself or look at what the task resolves to:

```julia
function start_async_print()
    start_time = time()
    t = @async try
        do_some_work(10)
    catch err
        bt = catch_backtrace()
        println()
        showerror(stderr, err, bt)
    end
    while !istaskdone(t)
        println("start() is waiting for do_some_work() to be done")
        sleep(1)
    end
end

function start_async_throw()
    start_time = time()
    t = do_some_work(10)
    while !istaskdone(t)
        println("start() is waiting for do_some_work() to be done")
        sleep(1)
    end
    wait(t) # or fetch(t)
end

```

gives

```julia
julia> start_async_print()
start() is waiting for do_some_work() to be done

UndefVarError: b not defined
Stacktrace:
 [1] do_some_work at ./untitled-8822451613b5304f5f50924dadde5d27:6 [inlined]
 [2] (::getfield(Main, Symbol("##27#28")))() at ./task.jl:259
julia> start_async_throw()
ERROR: UndefVarError: b not defined
Stacktrace:
 [1] do_some_work at ./untitled-8822451613b5304f5f50924dadde5d27:6 [inlined]
 [2] start_async_throw() at ./untitled-8822451613b5304f5f50924dadde5d27:33
 [3] top-level scope at none:0

```

The `wait`/`fetch` approach obviously doesn’t work very well when you don’t want to block.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-get-backtrace-of-async-task/18170)._
