bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
896 stars 250 forks source link

Detected blocking call to walk inside the event loop; power_profile.py, line 171 #2300

Closed frenck closed 1 week ago

frenck commented 2 weeks ago

System Health details

version core-2024.7.0.dev202406160221
installation_type Home Assistant OS
dev true
hassio true
docker true
user root
virtualenv false
python_version 3.12.2
os_name Linux
os_version 6.6.32-haos
arch x86_64
timezone Europe/Amsterdam
config_dir /config
Home Assistant Supervisor host_os | Home Assistant OS 12.4.dev20240612 -- | -- update_channel | dev supervisor_version | supervisor-2024.06.2.dev1002 agent_version | 1.6.0 docker_version | 26.1.4 disk_total | 468.7 GB disk_used | 103.6 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | board | generic-x86-64 supervisor_api | ok version_api | ok

Checklist

Describe the issue

Running the version listed in the above information, will throw warnings about this integration making blocking calls in the event loop.

Details are listed in the stack trace below.

Reproduction steps

  1. Update Home Assistant to 2024.7.0.dev202406160221 or newer
  2. Use this integration...

Debug logs

2024-06-16 22:52:21.083 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to walk inside the event loop by custom integration 'powercalc' at custom_components/powercalc/power_profile/power_profile.py, line 171: return sorted(next(os.walk(self.get_model_directory(True)))[1]) (offender: /config/custom_components/powercalc/power_profile/power_profile.py, line 171: return sorted(next(os.walk(self.get_model_directory(True)))[1])), please create a bug report at https://github.com/bramstroker/homeassistant-powercalc/issues
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 70, in wrapper
    return await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 368, in async_configure
    result = await self._async_configure(flow_id, user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 414, in _async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 517, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
  File "/config/custom_components/powercalc/config_flow.py", line 575, in async_step_library
    return await self.async_step_post_library(user_input)
  File "/config/custom_components/powercalc/config_flow.py", line 694, in async_step_post_library
    and self.power_profile.has_sub_profiles
  File "/config/custom_components/powercalc/power_profile/power_profile.py", line 175, in has_sub_profiles
    return len(self.get_sub_profiles()) > 0
  File "/config/custom_components/powercalc/power_profile/power_profile.py", line 171, in get_sub_profiles
    return sorted(next(os.walk(self.get_model_directory(True)))[1])

Diagnostics dump or YAML config

No response

bramstroker commented 1 week ago

Thanks raising the issue. Fixed with #2302

frenck commented 1 week ago

Nice! Awesome turnaround @bramstroker ❤️

../Frenck