Skip to content

Commit b95f264

Browse files
Richard Palethorperichiejp
authored andcommitted
asyncmap: Include original backtrace in rethrown exception
Collect the TaskExceptions into a CompositeException.
1 parent 191f2ae commit b95f264

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

base/asyncmap.jl

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function maptwice(wrapped_f, chnl, worker_tasks, c...)
175175
close(chnl)
176176

177177
# check and throw any exceptions from the worker tasks
178-
foreach(x->(v=fetch(x); isa(v, Exception) && throw(v)), worker_tasks)
178+
@sync foreach(t -> @sync_add(t), worker_tasks)
179179

180180
# check if there was a genuine problem with asyncrun
181181
(asyncrun_excp !== nothing) && throw(asyncrun_excp)
@@ -212,34 +212,26 @@ end
212212

213213
function start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing)
214214
t = @async begin
215-
retval = nothing
216-
217-
try
218-
if isa(batch_size, Number)
219-
while isopen(chnl)
220-
# The mapping function expects an array of input args, as it processes
221-
# elements in a batch.
222-
batch_collection=Any[]
223-
n = 0
224-
for exec_data in chnl
225-
push!(batch_collection, exec_data)
226-
n += 1
227-
(n == batch_size) && break
228-
end
229-
if n > 0
230-
exec_func(batch_collection)
231-
end
232-
end
233-
else
215+
if isa(batch_size, Number)
216+
while isopen(chnl)
217+
# The mapping function expects an array of input args, as it processes
218+
# elements in a batch.
219+
batch_collection=Any[]
220+
n = 0
234221
for exec_data in chnl
235-
exec_func(exec_data...)
222+
push!(batch_collection, exec_data)
223+
n += 1
224+
(n == batch_size) && break
225+
end
226+
if n > 0
227+
exec_func(batch_collection)
236228
end
237229
end
238-
catch e
239-
close(chnl)
240-
retval = e
230+
else
231+
for exec_data in chnl
232+
exec_func(exec_data...)
233+
end
241234
end
242-
retval
243235
end
244236
push!(worker_tasks, t)
245237
end

stdlib/Distributed/test/distributed_exec.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ let error_thrown = false
595595
try
596596
pmap(x -> x == 50 ? error("foobar") : x, 1:100)
597597
catch e
598-
@test e.captured.ex.msg == "foobar"
598+
@test e.exceptions[1].task.exception.captured.ex.msg == "foobar"
599599
error_thrown = true
600600
end
601601
@test error_thrown

0 commit comments

Comments
 (0)