proxystore.utils.tasks¶
Safely spawn asyncio background tasks with error handling.
exit_on_error
¶
Task callback that raises SystemExit on task exception.
Source code in proxystore/utils/tasks.py
spawn_guarded_background_task
¶
spawn_guarded_background_task(
coro: Callable[..., Coroutine[Any, Any, None]],
*args: Any,
**kwargs: Any
) -> Task[Any]
Run a coroutine safely in the background.
Launches the coroutine as an asyncio task and sets the done
callback to exit_on_error()
.
This is "safe" because it will ensure exceptions inside the task get logged
and cause the program to exit. Otherwise, background tasks that are not
awaited may not have their exceptions raised such that programs hang with
no notice of the exception that caused the hang.
Tasks can raise SafeTaskExit
to signal the task is finished but should not cause a system exit.
Source: https://stackoverflow.com/questions/62588076
Parameters:
-
coro
(Callable[..., Coroutine[Any, Any, None]]
) –Coroutine to run as task.
-
args
(Any
, default:()
) –Positional arguments for the coroutine.
-
kwargs
(Any
, default:{}
) –Keyword arguments for the coroutine.
Returns: