Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[homeassistant.util.loop] Detected blocking call to import_module with args #31

Open
danielholm opened this issue Jan 7, 2025 · 5 comments

Comments

@danielholm
Copy link

Hi,

In latest HA 2025.1 I get the following error in logs. The sensors keep working, however.
2025-01-05 16:47:05.866 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module with args ('dateparser.data.date_translation_data.en',) inside the event loop by custom integration 'resrobot' at custom_components/resrobot/sensor.py, line 120: time = dateparser.parse("in " + str(time_offset) + " minutes") (offender: /usr/local/lib/python3.13/site-packages/dateparser/languages/loader.py, line 215: import_module("dateparser.data.date_translation_data." + lang),), please create a bug report at https://github.com/TekniskSupport/home-assistant-resrobot/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module
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 227, in
sys.exit(main())
File "/usr/src/homeassistant/homeassistant/main.py", line 213, in main
exit_code = runner.run(runtime_conf)
File "/usr/src/homeassistant/homeassistant/runner.py", line 154, in run
return loop.run_until_complete(setup_and_run_hass(runtime_config))
File "/usr/local/lib/python3.13/asyncio/base_events.py", line 707, in run_until_complete
self.run_forever()
File "/usr/local/lib/python3.13/asyncio/base_events.py", line 678, in run_forever
self._run_once()
File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2033, in _run_once
handle._run()
File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run
self._context.run(self._callback, *self._args)
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2366, in _async_forward_entry_setup
result = await async_setup_component(
File "/usr/src/homeassistant/homeassistant/setup.py", line 165, in async_setup_component
result = await _async_setup_component(hass, domain, config)
File "/usr/src/homeassistant/homeassistant/setup.py", line 416, in async_setup_component
result = await task
File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 90, in async_setup
await component.async_setup(config)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 150, in async_setup
self.hass.async_create_task_internal(
File "/usr/src/homeassistant/homeassistant/core.py", line 832, in async_create_task_internal
task = create_eager_task(target, name=name, loop=self.loop)
File "/usr/src/homeassistant/homeassistant/util/async
.py", line 45, in create_eager_task
return Task(coro, loop=loop, name=name, eager_start=True)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 311, in async_setup_platform
await self._platforms[key].async_setup(platform_config, discovery_info)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 303, in async_setup
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_eager_task(awaitable, loop=hass.loop)
File "/usr/src/homeassistant/homeassistant/util/async
.py", line 45, in create_eager_task
return Task(coro, loop=loop, name=name, eager_start=True)
File "/config/custom_components/resrobot/sensor.py", line 80, in async_setup_platform
await add_sensors(
File "/config/custom_components/resrobot/sensor.py", line 120, in add_sensors
time = dateparser.parse("in " + str(time_offset) + " minutes")

@TekniskSupport
Copy link
Owner

Interesting
on line 120 i only use dateparser

it's imported on line 11, seems like there's some magic going on where it ignores the imports and then magically imports it whenever it is being used instead

That's kind of a neat trick to not having to import a lot of stuff that is not needed and keeps the scope clean, but in this case it seems to be causing issues rather than helping

Let me look into what i can do about it!

@Reedyn
Copy link

Reedyn commented Feb 11, 2025

I got the same issue. Let me know if you need any information.

@TekniskSupport
Copy link
Owner

@Reedyn I'm prtty sure this has to do with the time_offset configuration option used on this line:
https://github.com/TekniskSupport/home-assistant-resrobot/blob/master/custom_components/resrobot/sensor.py#L125

But not yet had the opportunity to have a look at the issue

@danielholm
Copy link
Author

I would like to help, but its beyond my understanding as of now.

@Reedyn
Copy link

Reedyn commented Feb 13, 2025

@Reedyn I'm prtty sure this has to do with the time_offset configuration option used on this line: https://github.com/TekniskSupport/home-assistant-resrobot/blob/master/custom_components/resrobot/sensor.py#L125

But not yet had the opportunity to have a look at the issue

I can confirm, when I removed the time_offset and rebooted Home Assistant the problem went away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants