Exec() with Timeout

Timeout with exec on javascript

Answered thanks to comments:
learn.js:

function qAsync(){
this.doAsync = function (ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
this.desc = "in order to wait 11.5 sec, call exec which calls doAsync, and see the print in the console"
this.exec = async function () {
await this.doAsync(11500);
console.log("did you see this after 11.5 sec?");
}
}

test.js:

async function test4(){
let test = new qAsync();
alert("first let us describe the function:\n"+test.desc);
alert("now we will run exec.");
await test.exec();
}

How to add a timeout to Runtime.exec() but checking exit value?

You can use p.exitValue() to get hold of the exit value, but note that you will get an IllegalThreadStateException if the subprocess represented by this Process object has not yet terminated so don't use this method if the waitFor() times out.

Process p = ...
if(!p.waitFor(1, TimeUnit.MINUTES)) {
//timeout - kill the process.
p.destroyForcibly();
} else {
int exitValue = p.exitValue();
// ...
}

Execute a shell function with timeout

timeout is a command - so it is executing in a subprocess of your bash shell. Therefore it has no access to your functions defined in your current shell.

The command timeout is given is executed as a subprocess of timeout - a grand-child process of your shell.

You might be confused because echo is both a shell built-in and a separate command.

What you can do is put your function in it's own script file, chmod it to be executable, then execute it with timeout.

Alternatively fork, executing your function in a sub-shell - and in the original process, monitor the progress, killing the subprocess if it takes too long.

Add timeout to Kubctl exec command

Use timeout parameter In check_output()

file_exist = subprocess. \
check_output("kubectl exec -it " + pod_name + " -- ls " +
path + " >> /dev/null 2>&1 && echo yes || echo no", shell=True,timeout=300).rstrip()
return file_exist == "yes"

https://docs.python.org/3/library/subprocess.html#subprocess.check_output

for kubectl exec timeout you can use --request-timeout=30s



Related Topics



Leave a reply



Submit