Spaces:
Running
Running
Download src/services/async_worker.py from akshayyy1/vector-auditor: direct link, hf CLI and curl.
- Browser
- Download file 400 Bytes
-
https://huggingface.co/spaces/akshayyy1/vector-auditor/resolve/main/src/services/async_worker.py
- Command line
-
hf download hf://spaces/akshayyy1/vector-auditor/src/services/async_worker.py
-
curl -L -o async_worker.py https://huggingface.co/spaces/akshayyy1/vector-auditor/resolve/main/src/services/async_worker.py
400 Bytes
| """Run sync functions in the default executor (non-blocking).""" | |
| import asyncio | |
| from typing import Any, Awaitable, Callable, TypeVar | |
| T = TypeVar("T") | |
| async def run_sync(fn: Callable[..., T], *args: Any, **kwargs: Any) -> T: | |
| """Run a blocking function in the default thread pool.""" | |
| loop = asyncio.get_running_loop() | |
| return await loop.run_in_executor(None, lambda: fn(*args, **kwargs)) | |