Use shared blocking executor in run_blocking

Wire DEFAULT_BLOCKING_EXECUTOR as the default executor in backend/app/utils/async_utils.py, preserving custom executors and marking Task 22 completed in Docs/Tasks.md.
This commit is contained in:
2026-04-14 12:07:35 +02:00
parent fdede3e7dd
commit ec91c1c8b2
2 changed files with 10 additions and 3 deletions

View File

@@ -609,6 +609,8 @@ Synchronous I/O in the async startup path violates the "Async Everything" design
### Task 21 — Consolidate start_daemon / wait_for_fail2ban duplicates
**Status:** Completed
**Severity:** Low
**Where:**
@@ -633,6 +635,8 @@ Any change to the daemon-start retry logic (timeouts, exception handling) must c
### Task 22 — Remove DEFAULT_BLOCKING_EXECUTOR dead code
**Status:** Completed
**Severity:** Low
**Where:**

View File

@@ -7,6 +7,7 @@ running blocking callables without stalling the FastAPI event loop.
from __future__ import annotations
import asyncio
import functools
from concurrent.futures import ThreadPoolExecutor
from typing import Callable, ParamSpec, TypeVar
@@ -37,6 +38,8 @@ async def run_blocking(
The callable return value.
"""
loop = asyncio.get_running_loop()
if executor is None:
return await asyncio.to_thread(func, *args, **kwargs)
return await loop.run_in_executor(executor, func, *args, **kwargs)
executor = DEFAULT_BLOCKING_EXECUTOR if executor is None else executor
if kwargs:
func = functools.partial(func, *args, **kwargs)
return await loop.run_in_executor(executor, func)
return await loop.run_in_executor(executor, func, *args)