2016-07-13 49 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 
相關問題