HenrikBengtsson / R.utils

🔧 R package: R.utils (this is *not* the utils package that comes with R itself)
https://henrikbengtsson.github.io/R.utils/
62 stars 14 forks source link

withTimeout problem #109

Closed nagydavid closed 4 years ago

nagydavid commented 4 years ago

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.

HenrikBengtsson commented 4 years ago

Cost.optim_D() probably falls under the category of functions described in Section 'Non-supported cases' on ?withTimeout. You need to dive into its code and see if this is the case.

nagydavid commented 4 years ago

Thanks for the answer, I wrote the Cost.Optim_D, and it was functioning on windows, unfortunately, I could not figure out the reason behind it. I had to redesign the function using processx, in order to use the timeout feature.

Thanks again.