我试图在函数超时时终止函数的执行。试图利用这里的帖子: 朱莉娅:你能在评估中设置时间限制吗
它在 RemoteRef 上出错是未定义的(我使用的是 v0.6.0(。将 RemoteRef 替换为 Channel(1(。现在错误是
方法错误: 没有方法匹配remotecall_fetch(::int64
, ::#test, ::字符串, ::字符串, ::字符串(addprocs(1)
@everywhere include("test.jl")
response = Channel(1)
@async put!(response, remotecall_fetch(2, test, arg1, arg2, arg3))
start=time()
while !isready(response) && (time() - start) < timeoutDuration
sleep(0.1)
end
elapsedtime = time()-start
错误(未处理的任务失败(: 方法错误: 没有方法匹配 remotecall_fetch(::Int64, ::#test, ::字符串
, ::字符串, ::字符串(也尝试过
@async put!(response, remotecall_fetch(2, ()->test(arg1, arg2, arg3)))
错误(未处理的任务失败(: 方法错误: 没有方法匹配 remotecall_fetch(::Int64, ::##10#12(
第二个工作线程找不到 test(( 吗?
根据文档:
help?> remotecall_fetch
search: remotecall_fetch remotecall_wait
remotecall_fetch(f, id::Integer, args...; kwargs...)
Perform fetch(remotecall(...)) in one message. Keyword arguments,
if any, are passed through to f. Any remote exceptions are captured
in a RemoteException and thrown.
See also fetch and remotecall.
remotecall_fetch(f, pool::AbstractWorkerPool, args...; kwargs...) -> result
WorkerPool variant of remotecall_fetch(f, pid, ....). Waits for and
takes a free worker from pool and performs a remotecall_fetch on it.
您需要这样做:
@async put!(response, remotecall_fetch(test, 2, arg1, arg2, arg3))
语法问题,worker# 应该在最后
@async put!(response, remotecall_fetch(()->test(a1,a2,a3),2) )