Skip to content

Commit

Permalink
Merge pull request #25 from neherlab/feat/emit-thread-errors
Browse files Browse the repository at this point in the history
Errors occurring in threads are now passed to an error channel. The main thread is waiting on this channel. Upon creation of the root graph the error channel is closed, and the main thread continues the execution.
  • Loading branch information
mmolari committed Mar 30, 2022
2 parents 0aa7711 + 2157523 commit c0662df
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/align.jl
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,6 @@ function align(Gs::Graph...; compare=Mash.distance, energy=(hit)->(-Inf), minblo
log("--> aligning pairs")

events = Channel{Bool}(10);
result = Channel{Graph}(1);

@spawn let
while isopen(events)
Expand All @@ -649,6 +648,9 @@ function align(Gs::Graph...; compare=Mash.distance, energy=(hit)->(-Inf), minblo
end
end

error_channel = Channel(1)

G = nothing
for clade postorder(tree)
@spawn try
if isleaf(clade)
Expand All @@ -667,16 +669,23 @@ function align(Gs::Graph...; compare=Mash.distance, energy=(hit)->(-Inf), minblo
if clade.parent !== nothing
put!(clade.parent.graph, G₀)
else
put!(result, G₀); close(result)
G = G₀
close(error_channel)
end
end
catch e
error(e)
catch err
put!(error_channel, [err, catch_backtrace()])
close(error_channel)
end
end

G = take!(result)
for (err, backtrace) in error_channel
@error "In-thread error during graph building:" exception=(err, backtrace)
error("graph construction failed, see above for stacktrace")
end

close(events)

return G
end

Expand Down

0 comments on commit c0662df

Please sign in to comment.