I’m unsure how to get the thrown error or backtrace of an asynchronous Task.
Here’s an example script:
# silent_test_all_in_one.jl function do_some_work(increase::Real) a = 0.0 start_time = time() while time() - start_time < 5 b += increase sleep(0.1) end a end function start_blocking() println("start() is waiting for do_some_work() to be done") do_some_work(10) end function start_async() start_time = time() t = @async do_some_work(10) while !istaskdone(t) println("start() is waiting for do_some_work() to be done") sleep(1) end end
To test, I did the following
- Save that file as “silent_test_all_in_one.jl” and include it at the REPL
start_blockingand see the appropriate error
start_asyncand don’t see any indication of an error
julia> include("silent_test_all_in_one.jl") start_async (generic function with 1 method) julia> start_blocking() start() is waiting for do_some_work() to be done ERROR: UndefVarError: b not defined Stacktrace:  do_some_work at C:\Users\dave\Documents\silent_test_all_in_one.jl:7 [inlined]  start_blocking() at C:\Users\dave\Documents\silent_test_all_in_one.jl:15  top-level scope at none:0 julia> start_async() start() is waiting for do_some_work() to be done julia> versioninfo() Julia Version 1.0.2 Commit d789231e99 (2018-11-08 20:11 UTC) Platform Info: OS: Windows (x86_64-w64-mingw32) CPU: Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-6.0.0 (ORCJIT, haswell)
Is this expected? Can this be avoided?
I’m working on a project that uses
HTTP.jl to handle some requests asynchronously with Tasks. Often, the code “hangs” in the REPL and gives no feedback and that’s when I realized that asynchronous
Taskss don’t seem to print out thrown errors or backtraces when the code actually errors out.