2016-07-13 47 views
6

我正在使用计算机集群运行很长时间的作业。有时,该过程会中断,我必须手动重新启动。当中断发生在一夜之间时,停机时间相当长。我想知道是否有办法在Julia中运行一个主管脚本来监视是否在另一个Julia实例中运行的作业。如果它被中断,它会重新启动进程,并在作业完成后终止。不幸的是,我不知道如何检查进程是否正在运行以及如何重新启动进程。这里是我的主要想法:如何自动重新启动Julia中的长时间作业

state = true 
while state == true 
    #check every minute 
    sleep(60) 
    data = readcsv("outputfile.csv") 
    #read file to check if process is finished 
    if size(data,1) < N 
     #some function to check if the process is running 
     if isrunning() == true 
      #Do nothing.Keep running 
     else 
     #some function to spawn new instance of julia 
     #run the code 
      include("myscript.jl") 
     end 
    else 
     #Job finished, exit while loop 
     state = false 
    end 
end 

回答

5

正确的工具为正确的工作。 使用你的命令行shell。 如果它不及时终止,它会给出一个错误状态码。

例如猛砸

until julia myscript.jl; 
do echo "Failed/Interrupted. Restarting in 5s. Press Ctrl-C now to interrupt."; 
sleep 5; 
done` 

因为Julia是不是unuable作为命令行亚军,你可以做,在朱莉娅

while true 
    try 
     run(`julia myscript.jl`) #Run a separate process 
     break 
    catch 
     println("Failed/Interrupted. Restarting in 5s. Press Ctrl-C now to interrupt.") 
     sleep(5) 
    end 
end 
相关问题