spacepy.toolbox.timeout_check_call

spacepy.toolbox.timeout_check_call(timeout, *args, **kwargs)[source]

Call a subprocess with a timeout.

Like subprocess.check_call(), but will terminate the process and raise TimeoutError if it runs for too long.

This will only terminate the single process started; any child processes will remain running (this has implications for, say, spawing shells.)

Parameters:
timeoutfloat

Timeout, in seconds. Fractions are acceptable but the resolution is of order 100ms.

argssequence

Arguments passed through to subprocess.Popen

kwargsdict

keyword arguments to pass to subprocess.Popen

Returns:
outint

0 on successful completion

Raises:
TimeoutError

If subprocess does not return in timeout seconds.

CalledProcessError

If command has non-zero exit status

Examples

>>> import spacepy.toolbox as tb
>>> tb.timeout_check_call(1, 'sleep 30', shell=True) #raises TimeoutError