Home Assistant Unofficial Reference 2024.12.1
homeassistant.util.async_ Namespace Reference

Functions

Task[_T] _T (Coroutine[Any, Any, _T] coro, *str|None name=None, AbstractEventLoop|None loop=None)
 
concurrent.futures.Future[_T_Ts (AbstractEventLoop loop, Callable[[*_Ts], _T] callback, **_Ts args)
 
bool cancelling (Future[Any] task)
 
Any gather_with_limited_concurrency (int limit, *Any tasks, bool return_exceptions=False)
 
list[TimerHandle] get_scheduled_timer_handles (AbstractEventLoop loop)
 
None shutdown_run_callback_threadsafe (AbstractEventLoop loop)
 

Variables

 _LOGGER = logging.getLogger(__name__)
 
string _SHUTDOWN_RUN_CALLBACK_THREADSAFE = "_shutdown_run_callback_threadsafe"
 

Detailed Description

Asyncio utilities.

Function Documentation

◆ _T()

Task[_T] homeassistant.util.async_._T ( Coroutine[Any, Any, _T]  coro,
*str | None   name = None,
AbstractEventLoop | None   loop = None 
)
private
Create a task from a coroutine and schedule it to run immediately.

Definition at line 25 of file async_.py.

◆ _Ts()

concurrent.futures.Future[_T] homeassistant.util.async_._Ts ( AbstractEventLoop  loop,
Callable[[*_Ts], _T callback,
**_Ts   args 
)
private
Submit a callback object to a given event loop.

Return a concurrent.futures.Future to access the result.

Definition at line 53 of file async_.py.

◆ cancelling()

bool homeassistant.util.async_.cancelling ( Future[Any]  task)
Return True if task is cancelling.

Definition at line 48 of file async_.py.

◆ gather_with_limited_concurrency()

Any homeassistant.util.async_.gather_with_limited_concurrency ( int  limit,
*Any  tasks,
bool   return_exceptions = False 
)
Wrap asyncio.gather to limit the number of concurrent tasks.

From: https://stackoverflow.com/a/61478547/9127614

Definition at line 101 of file async_.py.

◆ get_scheduled_timer_handles()

list[TimerHandle] homeassistant.util.async_.get_scheduled_timer_handles ( AbstractEventLoop  loop)
Return a list of scheduled TimerHandles.

Definition at line 137 of file async_.py.

◆ shutdown_run_callback_threadsafe()

None homeassistant.util.async_.shutdown_run_callback_threadsafe ( AbstractEventLoop  loop)
Call when run_callback_threadsafe should prevent creating new futures.

We must finish all callbacks before the executor is shutdown
or we can end up in a deadlock state where:

`executor.result()` is waiting for its `._condition`
and the executor shutdown is trying to `.join()` the
executor thread.

This function is considered irreversible and should only ever
be called when Home Assistant is going to shutdown and
python is going to exit.

Definition at line 120 of file async_.py.

Variable Documentation

◆ _LOGGER

homeassistant.util.async_._LOGGER = logging.getLogger(__name__)
private

Definition at line 20 of file async_.py.

◆ _SHUTDOWN_RUN_CALLBACK_THREADSAFE

string homeassistant.util.async_._SHUTDOWN_RUN_CALLBACK_THREADSAFE = "_shutdown_run_callback_threadsafe"
private

Definition at line 22 of file async_.py.