Run a command without blocking the event loop. Returns (returncode, stdout, stderr). Raises asyncio.TimeoutError after `timeout` seconds and FileNotFoundError if the binary is missing, like subprocess.run did. The child is killed on timeout or cancellation, so an abandoned request
(cmd: list[str], timeout: float)
| 289 | |
| 290 | |
| 291 | async def _run(cmd: list[str], timeout: float) -> tuple[int, str, str]: |
| 292 | """ |
| 293 | Run a command without blocking the event loop. Returns (returncode, |
| 294 | stdout, stderr). Raises asyncio.TimeoutError after `timeout` seconds and |
| 295 | FileNotFoundError if the binary is missing, like subprocess.run did. |
| 296 | |
| 297 | The child is killed on timeout or cancellation, so an abandoned request |
| 298 | never leaves an ffmpeg process running. |
| 299 | """ |
| 300 | proc = await asyncio.create_subprocess_exec( |
| 301 | *cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE |
| 302 | ) |
| 303 | try: |
| 304 | stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout) |
| 305 | except (asyncio.TimeoutError, asyncio.CancelledError): |
| 306 | proc.kill() |
| 307 | await proc.wait() |
| 308 | raise |
| 309 | return ( |
| 310 | proc.returncode, |
| 311 | stdout.decode(errors="replace"), |
| 312 | stderr.decode(errors="replace"), |
| 313 | ) |
| 314 | |
| 315 | |
| 316 | def _write_file(path: Path, video_b64: str, max_size_mb: float) -> None: |