1

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.

David Nagy
  • 11
  • 1
  • What exactly does `Cost.optim_D` do? There is a long list of "Non-Supported Cases" in the `?withTimeout` help page. – MrFlick Feb 14 '20 at 16:10
  • 1
    thank you for your answer, I solved the issue with processx library and dropped the withTimeout function – David Nagy Apr 30 '20 at 09:22

0 Answers0