mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Add os.walk to asyncio loop blocking detection (#118769)
This commit is contained in:
parent
53ab215dfc
commit
553311cc7d
@ -67,6 +67,9 @@ def enable() -> None:
|
|||||||
glob.iglob = protect_loop(
|
glob.iglob = protect_loop(
|
||||||
glob.iglob, strict_core=False, strict=False, loop_thread_id=loop_thread_id
|
glob.iglob, strict_core=False, strict=False, loop_thread_id=loop_thread_id
|
||||||
)
|
)
|
||||||
|
os.walk = protect_loop(
|
||||||
|
os.walk, strict_core=False, strict=False, loop_thread_id=loop_thread_id
|
||||||
|
)
|
||||||
|
|
||||||
if not _IN_TESTS:
|
if not _IN_TESTS:
|
||||||
# Prevent files being opened inside the event loop
|
# Prevent files being opened inside the event loop
|
||||||
|
@ -275,7 +275,7 @@ async def test_protect_loop_scandir(
|
|||||||
caplog.clear()
|
caplog.clear()
|
||||||
with contextlib.suppress(FileNotFoundError):
|
with contextlib.suppress(FileNotFoundError):
|
||||||
await hass.async_add_executor_job(os.scandir, "/path/that/does/not/exists")
|
await hass.async_add_executor_job(os.scandir, "/path/that/does/not/exists")
|
||||||
assert "Detected blocking call to listdir with args" not in caplog.text
|
assert "Detected blocking call to scandir with args" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_protect_loop_listdir(
|
async def test_protect_loop_listdir(
|
||||||
@ -290,3 +290,17 @@ async def test_protect_loop_listdir(
|
|||||||
with contextlib.suppress(FileNotFoundError):
|
with contextlib.suppress(FileNotFoundError):
|
||||||
await hass.async_add_executor_job(os.listdir, "/path/that/does/not/exists")
|
await hass.async_add_executor_job(os.listdir, "/path/that/does/not/exists")
|
||||||
assert "Detected blocking call to listdir with args" not in caplog.text
|
assert "Detected blocking call to listdir with args" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
async def test_protect_loop_walk(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
|
"""Test glob calls in the loop are logged."""
|
||||||
|
block_async_io.enable()
|
||||||
|
with contextlib.suppress(FileNotFoundError):
|
||||||
|
os.walk("/path/that/does/not/exists")
|
||||||
|
assert "Detected blocking call to walk with args" in caplog.text
|
||||||
|
caplog.clear()
|
||||||
|
with contextlib.suppress(FileNotFoundError):
|
||||||
|
await hass.async_add_executor_job(os.walk, "/path/that/does/not/exists")
|
||||||
|
assert "Detected blocking call to walk with args" not in caplog.text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user