【问题标题】:Julia function timeout using async and remotecall_fetch fails to find function使用异步和 remotecall_fetch 的 Julia 函数超时无法找到函数
【发布时间】:2018-07-09 19:54:42
【问题描述】:

我试图在函数超时时终止它的执行。试图利用这里的帖子:Julia: Can you set a time limit on eval

RemoteRef 上的错误未定义(我使用的是 v0.6.0)。将 RemoteRef 替换为 Channel(1)。现在错误是

MethodError: 没有匹配 remotecall_fetch 的方法 (::Int64, ::#test, ::String, ::String, ::String)

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

ERROR(未处理的任务失败):MethodError: no method matching remotecall_fetch(::Int64, ::#test, ::字符串, ::字符串, ::字符串)

也试过了

@async put!(response, remotecall_fetch(2, ()->test(arg1, arg2, arg3)))

ERROR(未处理的任务失败):MethodError: no method matching remotecall_fetch(::Int64, ::##10#12)

第二个工人找不到 test() 吗?

【问题讨论】:

    标签: asynchronous parallel-processing timeout julia


    【解决方案1】:

    语法问题,worker#应该在最后

    @async put!(response, remotecall_fetch(()->test(a1,a2,a3),2) )
    

    【讨论】:

      【解决方案2】:

      根据文档:

      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))
      

      【讨论】:

      • 我可以使用@time remotecall_fetch 来估计“测试”运行的实际持续时间吗?
      猜你喜欢
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      • 1970-01-01
      • 2012-07-25
      • 1970-01-01
      相关资源
      最近更新 更多