I have a Julia script that repeatedly calls a C++ program to perform an optimization. The C++ program writes a text file, then I have Julia read the results and decide what to do next. The problem is that occasionally (maybe 1 in 1000+ times) the C++ program freezes (the optimization probably gets stuck), and my entire script hangs indefinitely, making it very difficult for the script to make it through all necessary program calls. Is there a way I can add a timeout, so that if the program has not finished within 10 minutes I can restart with a new guess value?
Simplified example:
for k = 1:10
run(`program inputs`)
end
Desired:
max_runtime = 10*60 # 10 minutes
for k = 1:10
run(`program inputs`,max_runtime)
end
Alternative:
max_runtime = 10*60 # 10 minutes
for k = 1:10
deadline(function,max_runtime)
end