Spaces:
Sleeping
Sleeping
Download utils/async_helpers.py from yania-n/ProjectCraft: direct link, hf CLI and curl.
- Browser
- Download file 594 Bytes
-
https://huggingface.co/spaces/yania-n/ProjectCraft/resolve/main/utils/async_helpers.py
- Command line
-
hf download hf://spaces/yania-n/ProjectCraft/utils/async_helpers.py
-
curl -L -o async_helpers.py https://huggingface.co/spaces/yania-n/ProjectCraft/resolve/main/utils/async_helpers.py
594 Bytes
| """Async utility helpers for ProjectCraft.""" | |
| import asyncio | |
| from typing import Any, Callable | |
| async def run_in_executor(fn: Callable, *args) -> Any: | |
| """Run a synchronous function in a thread pool executor without blocking the event loop.""" | |
| loop = asyncio.get_event_loop() | |
| return await loop.run_in_executor(None, fn, *args) | |
| async def gather_with_errors(*coros) -> list: | |
| """ | |
| Run coroutines in parallel. Returns list of results. | |
| Failed coroutines return the exception object instead of raising. | |
| """ | |
| return await asyncio.gather(*coros, return_exceptions=True) | |