Skip to content

asyncmap hides actual error stack trace #41030

@marius311

Description

@marius311

Up to current master, asyncmap and single-worker pmap don't show you the stack trace to the actual error:

julia> foo(i) = error()
foo (generic function with 1 method)

julia> asyncmap(foo, 1:2)
ERROR: 
Stacktrace:
 [1] (::Base.var"#873#875")(x::Task)
   @ Base ./asyncmap.jl:177
 [2] foreach(f::Base.var"#873#875", itr::Vector{Any})
   @ Base ./abstractarray.jl:2576
 [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(foo), c::UnitRange{Int64}; ntasks::Int64, batch_size::Nothing)
   @ Base ./asyncmap.jl:103
 [6] #asyncmap#857
   @ ./asyncmap.jl:81 [inlined]
 [7] asyncmap(f::Function, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:81
 [8] top-level scope
   @ REPL[2]:1

julia> using Distributed

julia> nworkers()
1

julia> pmap(foo, 1:2)
ERROR: 
Stacktrace:
  [1] (::Base.var"#873#875")(x::Task)
    @ Base ./asyncmap.jl:177
  [2] foreach(f::Base.var"#873#875", itr::Vector{Any})
    @ Base ./abstractarray.jl:2576
  [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#858
    @ ./asyncmap.jl:103 [inlined]
  [6] #asyncmap#857
    @ ./asyncmap.jl:81 [inlined]
  [7] pmap(f::Function, p::WorkerPool, c::UnitRange{Int64}; distributed::Bool, batch_size::Int64, on_error::Nothing, retry_delays::Vector{Any}, retry_check::Nothing)
    @ Distributed /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/Distributed/src/pmap.jl:126
  [8] pmap(f::Function, p::WorkerPool, c::UnitRange{Int64})
    @ Distributed /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/Distributed/src/pmap.jl:101
  [9] pmap(f::Function, c::UnitRange{Int64}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Distributed /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/Distributed/src/pmap.jl:156
 [10] pmap(f::Function, c::UnitRange{Int64})
    @ Distributed /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/Distributed/src/pmap.jl:156
 [11] top-level scope
    @ REPL[7]:1

The single-worker pmap is particularly painful (for me at least) since often I want to debug first with a single worker, but then exactly in that case I don't get a stack trace (the multi-worker case does show it). There's a monkeypatched solution given in #36709 (comment) but would be great to have this fixed in Julia.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions