Spawns an asynchronous subprocess. Prepares the command and associated keyword arguments. If the `input` argument is provided, it checks to ensure that the `stdin` argument is not also provided. Once prepared, it creates and returns the subprocess. If the command executable is not found
(self, *command, **kwargs)
| 161 | |
| 162 | |
| 163 | async def _spawn_proc(self, *command, **kwargs): |
| 164 | """Spawns an asynchronous subprocess. |
| 165 | |
| 166 | Prepares the command and associated keyword arguments. If the `input` argument is provided, |
| 167 | it checks to ensure that the `stdin` argument is not also provided. Once prepared, it creates |
| 168 | and returns the subprocess. If the command executable is not found, it logs a warning and traceback. |
| 169 | |
| 170 | Args: |
| 171 | *command (str): The command to run as separate arguments. |
| 172 | **kwargs (dict): Additional keyword arguments for the subprocess. |
| 173 | |
| 174 | Raises: |
| 175 | ValueError: If both stdin and input arguments are provided. |
| 176 | |
| 177 | Returns: |
| 178 | tuple: A tuple containing the created process (or None if creation failed), the input (or None if not provided), |
| 179 | and the prepared command (or None if subprocess creation failed). |
| 180 | |
| 181 | Examples: |
| 182 | >>> _spawn_proc("ls", "-l", input="data") |
| 183 | (<Process ...>, "data", ["ls", "-l"]) |
| 184 | """ |
| 185 | try: |
| 186 | command, kwargs = self._prepare_command_kwargs(command, kwargs) |
| 187 | except SubprocessError as e: |
| 188 | command_str = " ".join([str(s) for s in command]) |
| 189 | log.warning(f"Error running command: '{command_str}': {e}") |
| 190 | log.trace(traceback.format_exc()) |
| 191 | return None, None, None |
| 192 | _input = kwargs.pop("input", None) |
| 193 | if _input is not None: |
| 194 | if kwargs.get("stdin") is not None: |
| 195 | raise ValueError("stdin and input arguments may not both be used.") |
| 196 | kwargs["stdin"] = asyncio.subprocess.PIPE |
| 197 | |
| 198 | log.hugeverbose(f"run: {' '.join(command)}") |
| 199 | try: |
| 200 | proc = await asyncio.create_subprocess_exec(*command, **kwargs) |
| 201 | return proc, _input, command |
| 202 | except FileNotFoundError as e: |
| 203 | log.warning(f"{e} - missing executable?") |
| 204 | log.trace(traceback.format_exc()) |
| 205 | return None, None, None |
| 206 | |
| 207 | |
| 208 | async def _write_proc_line(proc, chunk): |
nothing calls this directly
no test coverage detected
searching dependent graphs…