我正在使用一组计算机运行很长时间.有时,进程中断,我必须手动重启.隔夜发生中断时会有相当长的停机时间.我想知道是否有一种方法可以在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
Run Code Online (Sandbox Code Playgroud)
正确的工具适合正确的工作。使用命令行 shell。如果某些事情未及时终止,它将给出错误状态代码。
例如重击
until julia myscript.jl;
do echo "Failed/Interrupted. Restarting in 5s. Press Ctrl-C now to interrupt.";
sleep 5;
done`
Run Code Online (Sandbox Code Playgroud)
因为 Julia 并非无法作为命令行运行程序使用,所以在Julia中:
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
Run Code Online (Sandbox Code Playgroud)