Block detectable I/O in the event loop (#48387)
We added a warning when this happens last April and gave developers a year to fix the instability. We now prevent the instability by raising RuntimeError when code attempts to do known I/O in the event loop instead of the executor. We now provide a suggestion on how to fix the code that is causing the issue.
This commit is contained in:
parent
63e3012380
commit
b50dcef94f
2 changed files with 6 additions and 2 deletions
|
@ -136,6 +136,10 @@ def check_loop() -> None:
|
||||||
found_frame.lineno,
|
found_frame.lineno,
|
||||||
found_frame.line.strip(),
|
found_frame.line.strip(),
|
||||||
)
|
)
|
||||||
|
raise RuntimeError(
|
||||||
|
f"I/O must be done in the executor; Use `await hass.async_add_executor_job()` "
|
||||||
|
f"at {found_frame.filename[index:]}, line {found_frame.lineno}: {found_frame.line.strip()}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def protect_loop(func: Callable) -> Callable:
|
def protect_loop(func: Callable) -> Callable:
|
||||||
|
|
|
@ -78,7 +78,7 @@ async def test_check_loop_async():
|
||||||
|
|
||||||
async def test_check_loop_async_integration(caplog):
|
async def test_check_loop_async_integration(caplog):
|
||||||
"""Test check_loop detects when called from event loop from integration context."""
|
"""Test check_loop detects when called from event loop from integration context."""
|
||||||
with patch(
|
with pytest.raises(RuntimeError), patch(
|
||||||
"homeassistant.util.async_.extract_stack",
|
"homeassistant.util.async_.extract_stack",
|
||||||
return_value=[
|
return_value=[
|
||||||
Mock(
|
Mock(
|
||||||
|
@ -107,7 +107,7 @@ async def test_check_loop_async_integration(caplog):
|
||||||
|
|
||||||
async def test_check_loop_async_custom(caplog):
|
async def test_check_loop_async_custom(caplog):
|
||||||
"""Test check_loop detects when called from event loop with custom component context."""
|
"""Test check_loop detects when called from event loop with custom component context."""
|
||||||
with patch(
|
with pytest.raises(RuntimeError), patch(
|
||||||
"homeassistant.util.async_.extract_stack",
|
"homeassistant.util.async_.extract_stack",
|
||||||
return_value=[
|
return_value=[
|
||||||
Mock(
|
Mock(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue