home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.14k stars 29.82k forks source link

Detected blocking call to import_module inside the event loop by integration 'gdacs' #116478

Closed Mariusthvdb closed 1 week ago

Mariusthvdb commented 4 months ago

The problem

as title

What version of Home Assistant Core has the issue?

2024.5.0b4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

GDACS

Link to integration documentation on our website

https://www.home-assistant.io/integrations/gdacs

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.util.loop
Bron: util/loop.py:99
Eerst voorgekomen: 23:19:47 (1 gebeurtenissen)
Laatst gelogd: 23:19:47

Detected blocking call to import_module inside the event loop by integration 'gdacs' at homeassistant/components/gdacs/__init__.py, line 115: await self._feed_manager.update() (offender: /usr/local/lib/python3.12/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/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+gdacs%22

Additional information

No response

home-assistant[bot] commented 4 months ago

Hey there @exxamalte, mind taking a look at this issue as it has been labeled with an integration (gdacs) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `gdacs` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign gdacs` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


gdacs documentation gdacs source (message by IssueLinks)

Mariusthvdb commented 4 months ago

let me add that we also found this

2024-04-30 23:01:44.131 WARNING (MainThread) [asyncio] Executing <Task finished name='track time interval 300.0' coro=<GdacsFeedEntityManager.async_init.<locals>.update() done, defined at /usr/src/homeassistant/homeassistant/components/gdacs/__init__.py:102> result=None created at /usr/src/homeassistant/homeassistant/util/async_.py:40> took 0.526 seconds

as Bdraco says:

blocks the event loop for 0.5 every time it runs

not sure if its related, but figured it might be good to mention here at least

velkrosmaak commented 3 months ago

I get the same, albeit with Better Thermostat:

Detected blocking call to import_module inside the event loop by custom integration 'better_thermostat' at custom_components/better_thermostat/model_fixes/model_quirks.py, line 14: self.model_quirks = import_module( (offender: /config/custom_components/better_thermostat/model_fixes/model_quirks.py, line 14: self.model_quirks = import_module(), 

This is all I get in the logs regarding that component.

joostlek commented 3 months ago

@velkrosmaak please don't use this thread for that integration. Raise it at their issue tracker

Maarc commented 1 month ago

Hi!

FYI, I have the same warning message on HA 2024.7.4. Here is the full log entry, including the traceback:

2024-08-07 10:09:40.529 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module with args ('dateparser.data.date_translation_data.en',) inside the event loop by integration 'gdacs' at homeassistant/components/gdacs/__init__.py, line 115: await self._feed_manager.update() (offender: /usr/local/lib/python3.12/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/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+gdacs%22
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module
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 674, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, 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/components/gdacs/__init__.py", line 115, in async_update
    await self._feed_manager.update()
exxamalte commented 1 month ago

Thanks for the details. I believe I can now reconstruct where this issue is originated: The library used by this integration is aio-georss-gdacs which is based on library aio-georss-client which uses the dateparser library to parse date strings that are found in the GDACS RSS feed.

I am in control of the first two libraries, but I can't see any setting or option in the dateparser library to avoid that import_module call. Even if I limit the list of languages/locales to consider to English only (which would be OK for the GDACS feed) I believe that there would still at least be that one call to import the language settings on demand.

I'll have a look if there is maybe some alternative date parsing library available, or some setting in dateparser that I've overlooked.