mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix deadlock when restarting scripts (#49410)
This commit is contained in:
parent
83ecabe0a2
commit
a968dea152
@ -1212,13 +1212,8 @@ class Script:
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
async def _async_stop(
|
async def _async_stop(
|
||||||
self, update_state: bool, spare: _ScriptRun | None = None
|
self, aws: list[asyncio.Task], update_state: bool, spare: _ScriptRun | None
|
||||||
) -> None:
|
) -> None:
|
||||||
aws = [
|
|
||||||
asyncio.create_task(run.async_stop()) for run in self._runs if run != spare
|
|
||||||
]
|
|
||||||
if not aws:
|
|
||||||
return
|
|
||||||
await asyncio.wait(aws)
|
await asyncio.wait(aws)
|
||||||
if update_state:
|
if update_state:
|
||||||
self._changed()
|
self._changed()
|
||||||
@ -1227,7 +1222,15 @@ class Script:
|
|||||||
self, update_state: bool = True, spare: _ScriptRun | None = None
|
self, update_state: bool = True, spare: _ScriptRun | None = None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Stop running script."""
|
"""Stop running script."""
|
||||||
await asyncio.shield(self._async_stop(update_state, spare))
|
# Collect a a list of script runs to stop. This must be done before calling
|
||||||
|
# asyncio.shield as asyncio.shield yields to the event loop, which would cause
|
||||||
|
# us to wait for script runs added after the call to async_stop.
|
||||||
|
aws = [
|
||||||
|
asyncio.create_task(run.async_stop()) for run in self._runs if run != spare
|
||||||
|
]
|
||||||
|
if not aws:
|
||||||
|
return
|
||||||
|
await asyncio.shield(self._async_stop(aws, update_state, spare))
|
||||||
|
|
||||||
async def _async_get_condition(self, config):
|
async def _async_get_condition(self, config):
|
||||||
if isinstance(config, template.Template):
|
if isinstance(config, template.Template):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user