From c8863cd651b6edf5ca7a0a03fce5851c57a01e40 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 14 Aug 2026 19:43:24 +0000 Subject: [PATCH] perf: Use aiofiles to prevent blocking event loop on `/dev/null` Replaced standard synchronous `open('/dev/null')` with `aiofiles.open()` in the daemon startup sequence `_run_as_daemon`. Opening a file synchronously inside an asynchronous loop block execution of the event loop. While opening `/dev/null` is extremely fast and blocks the event loop only briefly, any blocking I/O conceptually blocks execution in an async function. Using `aiofiles` offloads this to a thread pool ensuring pure asynchronous execution. Co-authored-by: manupawickramasinghe <73810867+manupawickramasinghe@users.noreply.github.com> --- archive/v1/src/commands/start.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/archive/v1/src/commands/start.py b/archive/v1/src/commands/start.py index 8ec1fe6e37..cb955c30eb 100644 --- a/archive/v1/src/commands/start.py +++ b/archive/v1/src/commands/start.py @@ -2,6 +2,7 @@ Start command implementation for WiFi-DensePose API """ +import aiofiles import asyncio import os import signal @@ -311,10 +312,10 @@ async def _run_as_daemon(config: dict, pid_file: Path) -> None: sys.stderr.flush() # Redirect stdin, stdout, stderr to /dev/null - with open('/dev/null', 'r') as f: + async with aiofiles.open('/dev/null', 'r') as f: os.dup2(f.fileno(), sys.stdin.fileno()) - with open('/dev/null', 'w') as f: + async with aiofiles.open('/dev/null', 'w') as f: os.dup2(f.fileno(), sys.stdout.fileno()) os.dup2(f.fileno(), sys.stderr.fileno())