I am writing a Julia script for a scientific experiment and I want to put a time limit in calls made by the script. To solve this I tried to use this small package from @ararslan. The package works by creating a new worker process that will execute the call, while the main process will be pooling the channel associated to the remote call to check if it has finished, and will interrupt it if it is not finished by the time limit. However, it seems to not be working for me, and I reduced it to a MWE that I do not understand why it is not working. Maybe it is something basic, but I am not well versed in distributed computing.
import Distributed Distributed.@everywhere function f() return 42 end function ptimeout(f::Function, secs::Real; worker=1, poll=0.5, verbose=true) channel = Channel(1) @async begin println("start of @async block") value = remotecall_fetch(f, worker) println("remotecall_fetch returned") put!(channel, value) println("end of @async block") end println("passed the @async") timedwait( () -> (status = isready(channel); @show status; status), float(secs), pollint=float(poll) ) isready(channel) && return true verbose && @warn "Time limit for computation exceeded." Distributed.interrupt(worker) close(channel) println("reached ptimeout end") false end function main() worker_id = only(Distributed.addprocs(1)) @show ptimeout(f, 10; worker = worker_id) end main()
passed the @async status = false start of @async block status = false status = false status = false status = false ... ┌ Warning: Time limit for computation exceeded. └ @ Main ~/AreaDeTrabalho/mwe_timeout/mwe_timeout.jl:22
So, why my call to
Distributed.remotecall_fetch never returns, if the function I called is so simple that it just returns a constant value?