mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Ensure name of task is logged for unhandled loop exceptions (#118822)
This commit is contained in:
parent
709e32a38a
commit
72e4aee155
@ -137,16 +137,18 @@ def _async_loop_exception_handler(_: Any, context: dict[str, Any]) -> None:
|
|||||||
if source_traceback := context.get("source_traceback"):
|
if source_traceback := context.get("source_traceback"):
|
||||||
stack_summary = "".join(traceback.format_list(source_traceback))
|
stack_summary = "".join(traceback.format_list(source_traceback))
|
||||||
logger.error(
|
logger.error(
|
||||||
"Error doing job: %s: %s",
|
"Error doing job: %s (%s): %s",
|
||||||
context["message"],
|
context["message"],
|
||||||
|
context.get("task"),
|
||||||
stack_summary,
|
stack_summary,
|
||||||
**kwargs, # type: ignore[arg-type]
|
**kwargs, # type: ignore[arg-type]
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.error(
|
logger.error(
|
||||||
"Error doing job: %s",
|
"Error doing job: %s (%s)",
|
||||||
context["message"],
|
context["message"],
|
||||||
|
context.get("task"),
|
||||||
**kwargs, # type: ignore[arg-type]
|
**kwargs, # type: ignore[arg-type]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -115,11 +115,11 @@ def test_run_does_not_block_forever_with_shielded_task(
|
|||||||
tasks.append(asyncio.ensure_future(asyncio.shield(async_shielded())))
|
tasks.append(asyncio.ensure_future(asyncio.shield(async_shielded())))
|
||||||
tasks.append(asyncio.ensure_future(asyncio.sleep(2)))
|
tasks.append(asyncio.ensure_future(asyncio.sleep(2)))
|
||||||
tasks.append(asyncio.ensure_future(async_raise()))
|
tasks.append(asyncio.ensure_future(async_raise()))
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch.object(runner, "TASK_CANCELATION_TIMEOUT", 1),
|
patch.object(runner, "TASK_CANCELATION_TIMEOUT", 0.1),
|
||||||
patch("homeassistant.bootstrap.async_setup_hass", return_value=hass),
|
patch("homeassistant.bootstrap.async_setup_hass", return_value=hass),
|
||||||
patch("threading._shutdown"),
|
patch("threading._shutdown"),
|
||||||
patch("homeassistant.core.HomeAssistant.async_run", _async_create_tasks),
|
patch("homeassistant.core.HomeAssistant.async_run", _async_create_tasks),
|
||||||
@ -145,7 +145,7 @@ async def test_unhandled_exception_traceback(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
hass.loop.set_debug(True)
|
hass.loop.set_debug(True)
|
||||||
task = asyncio.create_task(_unhandled_exception())
|
task = asyncio.create_task(_unhandled_exception(), name="name_of_task")
|
||||||
await raised.wait()
|
await raised.wait()
|
||||||
# Delete it without checking result to trigger unhandled exception
|
# Delete it without checking result to trigger unhandled exception
|
||||||
del task
|
del task
|
||||||
@ -155,6 +155,7 @@ async def test_unhandled_exception_traceback(
|
|||||||
assert "Task exception was never retrieved" in caplog.text
|
assert "Task exception was never retrieved" in caplog.text
|
||||||
assert "This is unhandled" in caplog.text
|
assert "This is unhandled" in caplog.text
|
||||||
assert "_unhandled_exception" in caplog.text
|
assert "_unhandled_exception" in caplog.text
|
||||||
|
assert "name_of_task" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
def test_enable_posix_spawn() -> None:
|
def test_enable_posix_spawn() -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user