Skip to content

Commit 087dcf6

Browse files
authored
Print stacktraces from asyncmap'd tasks
```julia julia> f(i) = (sleep(i); i == 5 && error("5")) f (generic function with 1 method) julia> asyncmap(f, 1:5) # master ERROR: 5 Stacktrace: [1] (::Base.var"#881#883")(x::Task) @ Base ./asyncmap.jl:177 [2] foreach(f::Base.var"#881#883", itr::Vector{Any}) @ Base ./abstractarray.jl:2606 [3] maptwice(wrapped_f::Function, chnl::Channel{Any}, worker_tasks::Vector{Any}, c::UnitRange{Int64}) @ Base ./asyncmap.jl:177 [4] wrap_n_exec_twice @ ./asyncmap.jl:153 [inlined] [5] async_usemap(f::typeof(f), c::UnitRange{Int64}; ntasks::Int64, batch_size::Nothing) @ Base ./asyncmap.jl:103 [6] #asyncmap#865 @ ./asyncmap.jl:81 [inlined] [7] asyncmap(f::Function, c::UnitRange{Int64}) @ Base ./asyncmap.jl:81 [8] top-level scope @ REPL[4]:1 julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing) # monkeypatch t = @async begin retval = nothing try if isa(batch_size, Number) while isopen(chnl) # The mapping function expects an array of input args, as it processes # elements in a batch. batch_collection=Any[] n = 0 for exec_data in chnl push!(batch_collection, exec_data) n += 1 (n == batch_size) && break end if n > 0 exec_func(batch_collection) end end else for exec_data in chnl exec_func(exec_data...) end end catch e close(chnl) Base.display_error(stderr, Base.catch_stack()) retval = e end retval end push!(worker_tasks, t) end julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing) t = @async begin retval = nothing try if isa(batch_size, Number) while isopen(chnl) # The mapping function expects an array of input args, as it processes # elements in a batch. julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing) t = @async begin retval = nothing try if isa(batch_size, Number) while isopen(chnl) # The mapping function expects an array of input args, as it processes # elements in a batch. julia> asyncmap(f, 1:5) # post-patch ERROR: 5 Stacktrace: [1] error(s::String) @ Base ./error.jl:33 [2] f @ ./REPL[3]:1 [inlined] [3] (::Base.var"#871#876"{typeof(f)})(r::Base.RefValue{Any}, args::Tuple{Int64}) @ Base ./asyncmap.jl:100 [4] macro expansion @ ./REPL[5]:23 [inlined] [5] (::var"#1#2"{Base.var"#871#876"{typeof(f)}, Channel{Any}, Nothing})() @ Main ./task.jl:411 ERROR: 5 Stacktrace: [1] (::Base.var"#881#883")(x::Task) @ Base ./asyncmap.jl:177 [2] foreach(f::Base.var"#881#883", itr::Vector{Any}) @ Base ./abstractarray.jl:2606 [3] maptwice(wrapped_f::Function, chnl::Channel{Any}, worker_tasks::Vector{Any}, c::UnitRange{Int64}) @ Base ./asyncmap.jl:177 [4] wrap_n_exec_twice @ ./asyncmap.jl:153 [inlined] [5] async_usemap(f::typeof(f), c::UnitRange{Int64}; ntasks::Int64, batch_size::Nothing) @ Base ./asyncmap.jl:103 [6] #asyncmap#865 @ ./asyncmap.jl:81 [inlined] [7] asyncmap(f::Function, c::UnitRange{Int64}) @ Base ./asyncmap.jl:81 [8] top-level scope @ REPL[6]:1 ```
1 parent a163e37 commit 087dcf6

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

base/asyncmap.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ function start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing)
236236
end
237237
catch e
238238
close(chnl)
239+
display_error(stderr, catch_stack())
239240
retval = e
240241
end
241242
retval

0 commit comments

Comments
 (0)