4.6. sciexp2.exprun.wait¶
Source: sciexp2/exprun/wait.py
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.2. print_stringio¶
-
print_stringio(obj, out=None)¶ Print contents of a StringIO object as they become available.
Useful in combination with
stringioto print an output while processing it.Parameters: - obj : StringIO
StringIO object to print.
- out : file or function, optional
File or function to print object’s contents. Defaults to stdout.
See also
Examples
>>> stdout = StringIO.StringIO() >>> thread.start_new_thread(print_stringio, (stdout,)) >>> shell.run(["sh", "-c", "sleep 1 ; echo start ; sleep 2; echo end ; sleep 1"], ... stdout=stdout) start end
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.5. stringio¶
-
stringio(obj, pattern)¶ Wait until a StringIO’s contents match the given regex.
Useful to trigger operations when a process generates certain output.
See also
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