Skip to content

Commit 5d9c4cf

Browse files
add CachingPool method for remotecall
1 parent e4bd504 commit 5d9c4cf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/workerpool.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,28 @@ function remotecall_pool(rc_f, f, pool::CachingPool, args...; kwargs...)
400400
put!(pool, worker)
401401
end
402402
end
403+
404+
# Specialization for remotecall. We have to wait for the Future it returns
405+
# before putting the worker back in the pool.
406+
function remotecall_pool(rc_f::typeof(remotecall), f, pool::CachingPool, args...; kwargs...)
407+
worker = take!(pool)
408+
f_ref = get(pool.map_obj2ref, (worker, f), (f, RemoteChannel(worker)))
409+
isa(f_ref, Tuple) && (pool.map_obj2ref[(worker, f)] = f_ref[2]) # Add to tracker
410+
411+
local x
412+
try
413+
x = rc_f(exec_from_cache, worker, f_ref, args...; kwargs...)
414+
catch
415+
put!(pool, worker)
416+
rethrow()
417+
end
418+
419+
t = Threads.@spawn Threads.threadpool() try
420+
wait(x)
421+
finally
422+
put!(pool, worker)
423+
end
424+
errormonitor(t)
425+
426+
return x
427+
end

0 commit comments

Comments
 (0)