gpt4 book ai didi

julia - 如何在 Julia 中自动重启长时间工作

转载 作者:行者123 更新时间:2023-12-04 19:40:35 24 4
gpt4 key购买 nike

我正在使用一组计算机运行长时间的工作。有时,该过程会中断,我必须手动重新启动。当中断发生在一夜之间时,会出现相当长的停机时间。我想知道是否有办法在 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

最佳答案

适合工作的正确工具。
使用您的命令行 shell 。
如果它不合时宜地终止了某些东西,它会给出一个错误状态代码。

例如 重击

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

因为 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

关于julia - 如何在 Julia 中自动重启长时间工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38350078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com