academy.task¶
spawn_guarded_background_task
¶
spawn_guarded_background_task(
coro: Coroutine[Any, Any, Any],
*,
name: str,
log_exception: bool = True
) -> Task[Any]
Run a coroutine safely in the background.
Launches the coroutine as an asyncio task. Optionally attaches logging
to any exception raised, and/or exiting on any exception raised.
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(Coroutine[Any, Any, Any]) –Coroutine to run as task.
-
name(str) –name of background task. Unlike asyncio.create_task, this is required
-
log_exception(bool, default:True) –Write exception to the log. Set to false if exceptions are already logged by coro.
Returns: