代码之家  ›  专栏  ›  技术社区  ›  Tims

Julia函数超时使用async和remotecall\u fetch无法找到函数

  •  1
  • Tims  · 技术社区  · 7 年前

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

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

    MethodError:没有与remotecall\u 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
    

    错误(未处理的任务失败):MethodError:没有与remotecall\u fetch(::Int64,::#test, ::字符串,::字符串,::字符串)

    也尝试过

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

    错误(未处理的任务失败):MethodError:没有与remotecall\u fetch匹配的方法(::Int64,::##10#12)

    第二个工作进程是否无法找到test()?

    2 回复  |  直到 7 年前
        1
  •  0
  •   HarmonicaMuse    7 年前

    根据文件:

    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))
    
        2
  •  0
  •   Tims    7 年前

    语法问题,worker#应位于末尾

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