Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code to stop execution of another code

Tags:

r

exit

halt

I have a R code which does some data analysis and returns TRUE/FALSE. Sometimes, the input data is too large and the code just keeps running.

I want a script that will monitor my data analysis code and if it doesn't return anything, in say 600 seconds, then it halts the running code and do something else.

It will be like pressing STOP button on R console.

I know about stop, break, exit, etc. But these won't be useful because code won't reach to these statements as it is still running its data analysis loop.

like image 772
Sim101011 Avatar asked Mar 18 '16 12:03

Sim101011


People also ask

How do you stop the execution of the code?

To stop code execution in Python you first need to import the sys object. After this you can then call the exit() method to stop the program from running. It is the most reliable, cross-platform way of stopping code execution.

How do you stop a Python execution code?

Ctrl + C on Windows can be used to terminate Python scripts and Ctrl + Z on Unix will suspend (freeze) the execution of Python scripts. If you press CTRL + C while a script is running in the console, the script ends and raises an exception.

How do you stop an execution in java?

In Java exit() method is in java. This System. exit() method terminates the current JVM running on the system which results in termination of code being executed currently.

How do I stop execution in Visual Studio?

To end a debugging session in Microsoft Visual Studio, from the Debug menu, choose Stop Debugging.


1 Answers

You can use setTimeLimit() and have your main script call a secondary script which will have this function at the start.

setTimeLimit(elapsed = 10)
for(i in c(1:100)){
    cat(i,"\n")
    Sys.sleep(1)
}

this is an example of how you would expect it to work. After 10 seconds my job will reach the time limit, despite the loop wanting to count to 100, increasing an increment every second.

like image 101
zacdav Avatar answered Sep 30 '22 08:09

zacdav