Rename a method in exec_utils.
authorScott Gasch <[email protected]>
Fri, 3 Jun 2022 00:33:29 +0000 (17:33 -0700)
committerScott Gasch <[email protected]>
Fri, 3 Jun 2022 00:33:29 +0000 (17:33 -0700)
exec_utils.py
executors.py
tests/run_some_dependencies_test.py

index 7e45d92377d553ad5c5343158f49c5366faf12b6..0bcfc2771741040e79ae69d7bb93b02d85abe251 100644 (file)
@@ -71,7 +71,7 @@ def cmd_showing_output(
         return p.returncode
 
 
-def cmd_with_timeout(command: str, timeout_seconds: Optional[float] = None) -> int:
+def cmd_exitcode(command: str, timeout_seconds: Optional[float] = None) -> int:
     """Run a command but do not let it run for more than timeout_seconds.
     This code doesn't capture or rebroadcast the command's output.  It
     returns the exit value of the command or raises a TimeoutExpired
@@ -86,10 +86,10 @@ def cmd_with_timeout(command: str, timeout_seconds: Optional[float] = None) -> i
         the exit status of the subprocess once the subprocess has
         exited
 
-    >>> cmd_with_timeout('/bin/echo foo', 10.0)
+    >>> cmd_exitcode('/bin/echo foo', 10.0)
     0
 
-    >>> cmd_with_timeout('/bin/sleep 2', 0.01)
+    >>> cmd_exitcode('/bin/sleep 2', 0.01)
     Traceback (most recent call last):
     ...
     subprocess.TimeoutExpired: Command '['/bin/bash', '-c', '/bin/sleep 2']' timed out after 0.01 seconds
@@ -123,7 +123,6 @@ def cmd(command: str, timeout_seconds: Optional[float] = None) -> str:
     ret = subprocess.run(
         command,
         shell=True,
-        #        capture_output=True,
         stdout=subprocess.PIPE,
         stderr=subprocess.STDOUT,
         check=True,
index a9d25dad50ccff1b5b85594b84184fd2982d7c49..426937142437db6e46af93ec8ef6a17376ee8991 100644 (file)
@@ -36,7 +36,7 @@ import histogram as hist
 import string_utils
 from ansi import bg, fg, reset, underline
 from decorator_utils import singleton
-from exec_utils import cmd_in_background, cmd_with_timeout, run_silently
+from exec_utils import cmd_exitcode, cmd_in_background, run_silently
 from thread_utils import background_thread
 
 logger = logging.getLogger(__name__)
@@ -1380,7 +1380,7 @@ class DefaultExecutors(object):
     def _ping(host) -> bool:
         logger.debug('RUN> ping -c 1 %s', host)
         try:
-            x = cmd_with_timeout(f'ping -c 1 {host} >/dev/null 2>/dev/null', timeout_seconds=1.0)
+            x = cmd_exitcode(f'ping -c 1 {host} >/dev/null 2>/dev/null', timeout_seconds=1.0)
             return x == 0
         except Exception:
             return False
index c9f48a51a77d1b7c35bb1925e434198885d886ea..a7ee9b459b0240dfa2b0cda2c7074e6c20adf97f 100755 (executable)
@@ -32,7 +32,7 @@ class RunSomeDependenciesTest(unittest.TestCase):
         ]
         for command in commands:
             try:
-                ret = exec_utils.cmd_with_timeout(command, 15.0)
+                ret = exec_utils.cmd_exitcode(command, 15.0)
                 self.assertEqual(0, ret)
             except Exception as e:
                 logger.exception(e)