Skip to content

Commit

Permalink
Normalize worker_channel exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Sep 12, 2023
1 parent 662ad41 commit e4f5ca1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/DistributedStdlibWorker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function remote_do(f, w::DistributedStdlibWorker, args...; kwargs...)
end

function worker_channel(w::DistributedStdlibWorker, expr)
Core.eval(Main, quote
@transform_exception w Core.eval(Main, quote
$(Distributed).RemoteChannel(() -> Core.eval(Main, $(QuoteNode(expr))), $(w.pid))
end)
end
Expand Down
8 changes: 6 additions & 2 deletions src/Malt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,18 @@ remote_eval_wait(w::AbstractWorker, expr) = remote_eval_wait(Main, w, expr)
Malt.worker_channel(w::AbstractWorker, expr)
Create a channel to communicate with worker `w`. `expr` must be an expression
that evaluates to a Channel. `expr` should assign the Channel to a (global) variable
that evaluates to an `AbstractChannel`. `expr` should assign the channel to a (global) variable
so the worker has a handle that can be used to send messages back to the manager.
"""
function worker_channel(w::Worker, expr)
RemoteChannel(w, expr)
end
function worker_channel(w::InProcessWorker, expr)
Core.eval(w.host_module, expr)
remote_call_fetch(w) do
result = Core.eval(w.host_module, expr)
@assert result isa AbstractChannel
result
end
end


Expand Down
2 changes: 1 addition & 1 deletion src/worker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function handle(::Val{MsgType.special_serialization_failure}, socket, msg, msg_i
)
end

const _channel_cache = Dict{UInt64, Channel}()
const _channel_cache = Dict{UInt64, AbstractChannel}()

if abspath(PROGRAM_FILE) == @__FILE__
main()
Expand Down
16 changes: 8 additions & 8 deletions test/exceptions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ end


# TODO
# @test_throws(
# Exception,
# m.worker_channel(w, :(123))
# )
# @test_throws(
# Exception,
# m.worker_channel(w, :(sqrt(-1)))
# )
@test_throws(
Exception,
m.worker_channel(w, :(123))
)
@test_throws(
m.RemoteException,
m.worker_channel(w, :(sqrt(-1)))
)
@test m.remote_call_fetch(&, w, true, true)
end

Expand Down

0 comments on commit e4f5ca1

Please sign in to comment.