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:
@@ -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
|
### Task 21 — Consolidate start_daemon / wait_for_fail2ban duplicates
|
||||||
|
|
||||||
|
**Status:** Completed
|
||||||
|
|
||||||
**Severity:** Low
|
**Severity:** Low
|
||||||
|
|
||||||
**Where:**
|
**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
|
### Task 22 — Remove DEFAULT_BLOCKING_EXECUTOR dead code
|
||||||
|
|
||||||
|
**Status:** Completed
|
||||||
|
|
||||||
**Severity:** Low
|
**Severity:** Low
|
||||||
|
|
||||||
**Where:**
|
**Where:**
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ running blocking callables without stalling the FastAPI event loop.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import functools
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from typing import Callable, ParamSpec, TypeVar
|
from typing import Callable, ParamSpec, TypeVar
|
||||||
|
|
||||||
@@ -37,6 +38,8 @@ async def run_blocking(
|
|||||||
The callable return value.
|
The callable return value.
|
||||||
"""
|
"""
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
if executor is None:
|
executor = DEFAULT_BLOCKING_EXECUTOR if executor is None else executor
|
||||||
return await asyncio.to_thread(func, *args, **kwargs)
|
if kwargs:
|
||||||
return await loop.run_in_executor(executor, func, *args, **kwargs)
|
func = functools.partial(func, *args, **kwargs)
|
||||||
|
return await loop.run_in_executor(executor, func)
|
||||||
|
return await loop.run_in_executor(executor, func, *args)
|
||||||
|
|||||||
Reference in New Issue
Block a user