mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Optimize subprocess performance with close_fds=False (#10145)
This commit is contained in:
		| @@ -36,7 +36,9 @@ def get_sdl_options(value): | ||||
|     if value != "": | ||||
|         return value | ||||
|     try: | ||||
|         return subprocess.check_output(["sdl2-config", "--cflags", "--libs"]).decode() | ||||
|         return subprocess.check_output( | ||||
|             ["sdl2-config", "--cflags", "--libs"], close_fds=False | ||||
|         ).decode() | ||||
|     except Exception as e: | ||||
|         raise cv.Invalid("Unable to run sdl2-config - have you installed sdl2?") from e | ||||
|  | ||||
|   | ||||
| @@ -229,6 +229,7 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler): | ||||
|                 stdin=subprocess.PIPE, | ||||
|                 stdout=subprocess.PIPE, | ||||
|                 stderr=subprocess.STDOUT, | ||||
|                 close_fds=False, | ||||
|             ) | ||||
|             stdout_thread = threading.Thread(target=self._stdout_thread) | ||||
|             stdout_thread.daemon = True | ||||
|   | ||||
| @@ -17,7 +17,9 @@ _LOGGER = logging.getLogger(__name__) | ||||
| def run_git_command(cmd, cwd=None) -> str: | ||||
|     _LOGGER.debug("Running git command: %s", " ".join(cmd)) | ||||
|     try: | ||||
|         ret = subprocess.run(cmd, cwd=cwd, capture_output=True, check=False) | ||||
|         ret = subprocess.run( | ||||
|             cmd, cwd=cwd, capture_output=True, check=False, close_fds=False | ||||
|         ) | ||||
|     except FileNotFoundError as err: | ||||
|         raise cv.Invalid( | ||||
|             "git is not installed but required for external_components.\n" | ||||
|   | ||||
| @@ -114,7 +114,9 @@ def cpp_string_escape(string, encoding="utf-8"): | ||||
| def run_system_command(*args): | ||||
|     import subprocess | ||||
|  | ||||
|     with subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p: | ||||
|     with subprocess.Popen( | ||||
|         args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=False | ||||
|     ) as p: | ||||
|         stdout, stderr = p.communicate() | ||||
|         rc = p.returncode | ||||
|         return rc, stdout, stderr | ||||
|   | ||||
| @@ -211,7 +211,7 @@ def _decode_pc(config, addr): | ||||
|         return | ||||
|     command = [idedata.addr2line_path, "-pfiaC", "-e", idedata.firmware_elf_path, addr] | ||||
|     try: | ||||
|         translation = subprocess.check_output(command).decode().strip() | ||||
|         translation = subprocess.check_output(command, close_fds=False).decode().strip() | ||||
|     except Exception:  # pylint: disable=broad-except | ||||
|         _LOGGER.debug("Caught exception for command %s", command, exc_info=1) | ||||
|         return | ||||
|   | ||||
| @@ -239,7 +239,12 @@ def run_external_process(*cmd: str, **kwargs: Any) -> int | str: | ||||
|  | ||||
|     try: | ||||
|         proc = subprocess.run( | ||||
|             cmd, stdout=sub_stdout, stderr=sub_stderr, encoding="utf-8", check=False | ||||
|             cmd, | ||||
|             stdout=sub_stdout, | ||||
|             stderr=sub_stderr, | ||||
|             encoding="utf-8", | ||||
|             check=False, | ||||
|             close_fds=False, | ||||
|         ) | ||||
|         return proc.stdout if capture_stdout else proc.returncode | ||||
|     except KeyboardInterrupt:  # pylint: disable=try-except-raise | ||||
|   | ||||
		Reference in New Issue
	
	Block a user