4.6. sciexp2.exprun.wait

Source: sciexp2/exprun/wait.py

Functions to wait on remote connections and process output.

Functions

connection Wait until we can connect to given address/port.
print_stringio Print contents of a StringIO object as they become available.
run Run command with a timeout.
ssh Wait until we can ssh through given shell.
stringio Wait until a StringIO’s contents match the given regex.

4.6.1. connection

connection(shell, address, port, timeout=0)

Wait until we can connect to given address/port.

4.6.3. run

run(shell, *args, **kwargs)

Run command with a timeout.

Parameters:
shell

Shell used to run given command.

timeout : int, optional

Timeout before erroring out (in seconds). Default is no timeout.

rerun_error : bool, optional

Rerun command every time it fails. Default is False.

args, kwargs

Paramaters to the shell’s spawn method.

Returns:
spur.ExecutionResult

4.6.4. ssh

ssh(shell, timeout=0)

Wait until we can ssh through given shell.

4.6.5. stringio

stringio(obj, pattern, timeout=0)

Wait until a StringIO’s contents match the given regex.

Useful to trigger operations when a process generates certain output.

See also

print_stringio

Examples

Count time between the “start” and “end” lines printed by a process:

>>> stdout = io.StringIO()
>>> def timer(obj):
        stringio(obj, "^start$")
        t_start = time.time()
        stringio(obj, "^end$")
        t_end = time.time()
        print("time:", int(t_end - t_start))
>>> thread.start_new_thread(timer, (stdout,))
>>> shell.run(["sh", "-c", "sleep 1 ; echo start ; sleep 2; echo end ; sleep >>> 1"],
...           stdout=stdout)
time: 2