Make smart futures avoid polling.
[python_utils.git] / exec_utils.py
index 7e9dae51fe564883db085ecf1505fce9c9ab39e7..89cfbd7bf15f23a7a0effaed24954f7b4480aded 100644 (file)
@@ -1,11 +1,15 @@
 #!/usr/bin/env python3
 
 import atexit
+import logging
 import shlex
 import subprocess
 from typing import List, Optional
 
 
+logger = logging.getLogger(__file__)
+
+
 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.
@@ -72,6 +76,7 @@ def cmd_in_background(
                                    stderr=subprocess.DEVNULL)
     else:
         subproc = subprocess.Popen(args, stdin=subprocess.DEVNULL)
+
     def kill_subproc() -> None:
         try:
             if subproc.poll() is None:
@@ -79,7 +84,7 @@ def cmd_in_background(
                 subproc.terminate()
                 subproc.wait(timeout=10.0)
         except BaseException as be:
-            log.error(be)
+            logger.exception(be)
     atexit.register(kill_subproc)
     return subproc