-
Notifications
You must be signed in to change notification settings - Fork 61
Closed
Description
Bug Report: Blocking call to import_module in event loop causing stability issues
Description
Home Assistant detects a blocking import_module call in the event loop that is causing stability issues. The call occurs when loading the pyscript custom component.
Environment
- Home Assistant Version: 2026.1.0
- Python Version: 3.13
- Affected Integration:
pyscript(Custom Component) - Installation Type: Home Assistant OS
Error Log
Detected blocking call to import_module with args ('custom_components.pyscript',) in
/usr/src/homeassistant/homeassistant/loader.py, line 1078:
ComponentProtocol, importlib.import_module(self.pkg_path) inside the event loop;
This is causing stability issues.
Full Traceback
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 229, in <module>
sys.exit(main())
File "/usr/src/homeassistant/homeassistant/__main__.py", line 215, in main
exit_code = runner.run(runtime_conf)
File "/usr/src/homeassistant/homeassistant/runner.py", line 289, in run
return loop.run_until_complete(setup_and_run_hass(runtime_config))
File "/usr/local/lib/python3.13/asyncio/base_events.py", line 712, in run_until_complete
self.run_forever()
File "/usr/local/lib/python3.13/asyncio/base_events.py", line 683, in run_forever
self._run_once()
File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2050, 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/setup.py", line 170, in async_setup_component
result = await _async_setup_component(hass, domain, config)
File "/usr/src/homeassistant/homeassistant/setup.py", line 343, in _async_setup_component
component = await integration.async_get_component()
File "/usr/src/homeassistant/homeassistant/loader.py", line 1030, in async_get_component
comp = self._get_component()
File "/usr/src/homeassistant/homeassistant/loader.py", line 1078, in _get_component
ComponentProtocol, importlib.import_module(self.pkg_path)Problem
The importlib.import_module() call is executed synchronously within the async event loop, leading to blocking I/O operations that compromise Home Assistant's stability.
Expected Behavior
The import should be performed asynchronously or in a separate thread to avoid blocking the event loop.
Reproducibility
- Occurs during Home Assistant startup
- Happens when loading the
pyscriptcustom component - Reproducible on every restart with the pyscript integration installed
Additional Information
- Reference to Developer Documentation: https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module
- Affected file:
/usr/src/homeassistant/homeassistant/loader.py, line 1078 - The issue appears to be related to Python 3.13 and its stricter asyncio checks
Possible Solution
The import should be offloaded to an executor using await hass.async_add_executor_job() or a similar mechanism to prevent blocking the event loop.
ALERTua
Metadata
Metadata
Assignees
Labels
No labels