I ran into some problem.
I have a code which I made on Windows, and I now trying to use it on Linux(Ubuntu).
Cost.optim_D.kill<- function(x,RunFile,showLogFile,PathToDaisy,ctrldaisy){
tryCatch(R.utils::withTimeout(Cost.optim_D(x,RunFile,showLogFile,PathToDaisy,ctrldaisy),
timeout = 60,
onTimeout="error"),
error = function(ex) {
PID<-system(paste0('pgrep daisy', Sys.getpid()))
KILL.daisy <- paste0('kill -9 ',PID)
system(KILL.daisy)
daisy_new <- paste0("/opt/daisy/bin/daisy", Sys.getpid())
if(file.exists(daisy_new)){file.remove(daisy_new)}
return(runif(1,200,1000))
})}
The code functionality to execute an external program and if that program runs longer than 60 seconds, then the withTimeout, throw an error, and the tryCatch, execute a killing process system function.
This function works well on Windows environment, but in Linux, withTimeout doesnt throw the error after the time limit, while the extrenal Program is running.