bremor / bureau_of_meteorology

Custom component for retrieving weather information from the Bureau of Meteorology.
MIT License
186 stars 31 forks source link

Detected blocking call to open inside the event loop #222

Closed OzGav closed 3 months ago

OzGav commented 4 months ago

Warning in logs noticed with HA 2024.6.0b1

Detected blocking call to open inside the event loop by custom integration 'bureau_of_meteorology' at custom_components/bureau_of_meteorology/sensor.py, line 237: tzinfo = pytz.timezone(self.collector.locations_data["data"]["timezone"]) (offender: /usr/local/lib/python3.12/site-packages/pytz/init.py, line 108: return open(filename, 'rb')), please create a bug report at https://github.com/bremor/bureau_of_meteorology/issues

tomlut commented 3 months ago

There appears to be more data provided in the log now:

Logger: homeassistant.util.loop Source: util/loop.py:84 First occurred: 13:01:15 (650 occurrences) Last logged: 13:01:49

Detected blocking call to open inside the event loop by custom integration 'bureau_of_meteorology' at custom_components/bureau_of_meteorology/sensor.py, line 237: tzinfo = pytz.timezone(self.collector.locations_data["data"]["timezone"]) (offender: /usr/local/lib/python3.12/site-packages/pytz/init.py, line 108: return open(filename, 'rb')), please create a bug report at https://github.com/bremor/bureau_of_meteorology/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in 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 188, 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/src/homeassistant/homeassistant/config_entries.py", line 2055, in async_forward_entry_setup return await self._async_forward_entry_setup(entry, domain, True) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2081, in _async_forward_entry_setup await entry.async_setup(self.hass, integration=integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 134, in async_setup_entry return await component.async_setup_entry(entry) File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 196, in async_setup_entry return await self._platforms[key].async_setup_entry(config_entry) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 333, in async_setup_entry return await self._async_setup_platform(async_create_setup_awaitable) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 363, in _async_setup_platform awaitable = create_eagertask(awaitable, loop=hass.loop) File "/usr/src/homeassistant/homeassistant/util/async.py", line 37, in create_eager_task return Task(coro, loop=loop, name=name, eager_start=True) File "/config/custom_components/bureau_of_meteorology/sensor.py", line 171, in async_setup_entry async_add_entities(new_entities, update_before_add=False) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 515, in _async_schedule_add_entities_for_entry task = self.config_entry.async_create_task( File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1134, in async_create_task task = hass.async_create_task_internal( File "/usr/src/homeassistant/homeassistant/core.py", line 828, in async_create_task_internal task = create_eagertask(target, name=name, loop=self.loop) File "/usr/src/homeassistant/homeassistant/util/async.py", line 37, in create_eager_task return Task(coro, loop=loop, name=name, eager_start=True) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 649, in async_add_entities await add_func(coros, entities, timeout) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 600, in _async_add_entities await coro File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 914, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1354, in add_to_platform_finish await self.async_added_to_hass() File "/config/custom_components/bureau_of_meteorology/sensor.py", line 199, in async_added_to_hass self._update_callback() File "/config/custom_components/bureau_of_meteorology/sensor.py", line 203, in _update_callback self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1000, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1126, in _async_write_ha_state state, attr, capabilities, shadowed_attr = self.async_calculate_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1065, in async_calculate_state if extra_state_attributes := self.extra_state_attributes: File "/config/custom_components/bureau_of_meteorology/sensor.py", line 237, in extra_state_attributes tzinfo = pytz.timezone(self.collector.locations_data["data"]["timezone"]) Detected blocking call to open inside the event loop by custom integration 'watchman' at custom_components/watchman/utils.py, line 258: for i, line in enumerate(open(yaml_file, encoding="utf-8")): (offender: /config/custom_components/watchman/utils.py, line 258: for i, line in enumerate(open(yaml_file, encoding="utf-8")):), please create a bug report at https://github.com/dummylabs/thewatchman/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in 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 188, 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/src/homeassistant/homeassistant/runner.py", line 164, in setup_and_run_hass return await hass.async_run() File "/usr/src/homeassistant/homeassistant/core.py", line 515, in async_run await self.async_start() File "/usr/src/homeassistant/homeassistant/core.py", line 568, in async_start self.bus.async_fire_internal(EVENT_HOMEASSISTANT_STARTED) File "/usr/src/homeassistant/homeassistant/core.py", line 1554, in async_fire_internal self._hass.async_run_hass_job(job, event) File "/usr/src/homeassistant/homeassistant/core.py", line 936, in async_run_hass_job hassjob.target(args) File "/usr/src/homeassistant/homeassistant/core.py", line 1418, in call self.hass.async_run_hass_job(self.listener_job, event) File "/usr/src/homeassistant/homeassistant/core.py", line 939, in async_run_hass_job return self._async_add_hass_job(hassjob, args, background=background) File "/usr/src/homeassistant/homeassistant/core.py", line 748, in _async_add_hass_job task = create_eagertask( File "/usr/src/homeassistant/homeassistant/util/async.py", line 37, in create_eager_task return Task(coro, loop=loop, name=name, eager_start=True) File "/config/custom_components/watchman/init.py", line 274, in async_on_home_assistant_started parse_config(hass, reason="HA restart") File "/config/custom_components/watchman/init.py", line 351, in parse_config entity_list, service_list, files_parsed, files_ignored = parse( File "/config/custom_components/watchman/utils.py", line 258, in parse for i, line in enumerate(open(yaml_file, encoding="utf-8")):

tomlut commented 3 months ago

Yes, there have been changes to Home Assistant to detect this. Many third party integrations suffer from it. Your post is off topic here.

gregeeh commented 3 months ago

I'm getting the same error. Why it is off topic?

tomlut commented 3 months ago

Because it had nothing to do with this bureau_of_meteorology integration. It was for a completely different integration. You report the warning (not error) in the github repository that caused it, not a completely unrelated one.

gregeeh commented 3 months ago

Thanks for your quick reply.

I'm really sorry but I don't understand your comment "it had nothing to do with this bureau_of_meteorology Integration" when the error states "please create a bug report at https://github.com/bremor/bureau_of_meteorology/issues"

tomlut commented 3 months ago

Sorry I thought you were the other person who's comment has since been deleted.

This identical error also just started occurring in another custom integration that I use.

Conversation in this issue may privide clues; [BJReplay/ha-solcast-solar#14](https://github.com/BJReplay/ha-solcast-solar/issues/14)

As you can see, they had an issue with the solcast not BoM integration.

gregeeh commented 3 months ago

OK, thanks for the explanation.

Makin-Things commented 3 months ago

Fix by release 1.3.2. Thanks @dbiczo