Spaces:
Sleeping
Sleeping
Download core/executor.py from Qurrah/replyflow-rag: direct link, hf CLI and curl.
- Browser
- Download file 463 Bytes
-
https://huggingface.co/spaces/Qurrah/replyflow-rag/resolve/main/core/executor.py
- Command line
-
hf download hf://spaces/Qurrah/replyflow-rag/core/executor.py
-
curl -L -o executor.py https://huggingface.co/spaces/Qurrah/replyflow-rag/resolve/main/core/executor.py
463 Bytes
| # runs blocking (synchronous) functions without freezing your async FastAPI server. | |
| import asyncio | |
| from collections.abc import Callable | |
| from concurrent.futures import Executor | |
| from functools import partial | |
| from typing import TypeVar | |
| T = TypeVar("T") | |
| async def run_blocking(executor: Executor, func: Callable[..., T], *args, **kwargs) -> T: | |
| loop = asyncio.get_running_loop() | |
| return await loop.run_in_executor(executor, partial(func, *args, **kwargs)) | |