+logger = logging.getLogger(__file__)
+
+
+def cmd_showing_output(command: str) -> None:
+ p = subprocess.Popen(
+ command,
+ shell=True,
+ bufsize=0,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ )
+ for line in iter(p.stdout.readline, b''):
+ print(line.decode('utf-8'), end='')
+ p.stdout.close()
+ p.wait()
+
+
+def cmd_with_timeout(command: str, timeout_seconds: Optional[float]) -> int:
+ """
+ Run a command but do not let it run for more than timeout seconds.
+
+ >>> cmd_with_timeout('/bin/echo foo', 10.0)
+ 0
+
+ >>> cmd_with_timeout('/bin/sleep 2', 0.1)
+ Traceback (most recent call last):
+ ...
+ subprocess.TimeoutExpired: Command '['/bin/bash', '-c', '/bin/sleep 2']' timed out after 0.1 seconds
+
+ """