Avoid blocking operations in event loop #145
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
According to https://developers.home-assistant.io/docs/asyncio_blocking_operations/ we should not use blocking calls in the event loop, which is also indicated as a warning at HA startup:
Logger: homeassistant.util.loop
Quelle: util/loop.py:136
Erstmals aufgetreten: 08:53:23 (1 Vorkommnisse)
Zuletzt protokolliert: 08:53:23
Detected blocking call to open with args ('/usr/share/zoneinfo/UTC', 'rb') inside the event loop by custom integration 'ical' at custom_components/ical/__init__.py, line 888: indate = indate.replace(tzinfo=gettz(str(indate.tzinfo))) (offender: /home/vscode/.local/ha-venv/lib/python3.12/site-packages/dateutil/tz/tz.py, line 464: fileobj = open(fileobj, 'rb')), please create a bug report at https://github.com/tybritten/ical-sensor-homeassistant/issues For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open Traceback (most recent call last): File "/usr/local/lib/python3.12/runpy.py", line 198, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/local/lib/python3.12/runpy.py", line 88, in _run_code exec(code, run_globals) File "/home/vscode/.vscode-server/extensions/ms-python.debugpy-2024.10.0-linux-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module> cli.main() File "/home/vscode/.vscode-server/extensions/ms-python.debugpy-2024.10.0-linux-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main run() File "/home/vscode/.vscode-server/extensions/ms-python.debugpy-2024.10.0-linux-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 317, in run_module run_module_as_main(options.target, alter_argv=True) File "/home/vscode/.vscode-server/extensions/ms-python.debugpy-2024.10.0-linux-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 238, in _run_module_as_main return _run_code(code, main_globals, None, File "/home/vscode/.vscode-server/extensions/ms-python.debugpy-2024.10.0-linux-arm64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code exec(code, run_globals) File "/workspaces/core/homeassistant/__main__.py", line 223, in <module> sys.exit(main()) File "/workspaces/core/homeassistant/__main__.py", line 209, in main exit_code = runner.run(runtime_conf) File "/workspaces/core/homeassistant/runner.py", line 189, 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 1978, 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 "/workspaces/core/config/custom_components/ical/sensor.py", line 33, in async_setup_entry await ical_events.update() File "/workspaces/core/config/custom_components/ical/__init__.py", line 595, in update self.calendar = self._ical_parser( File "/workspaces/core/config/custom_components/ical/__init__.py", line 792, in _ical_parser dtstart = self._ical_date_fixer( File "/workspaces/core/config/custom_components/ical/__init__.py", line 888, in _ical_date_fixer indate = indate.replace(tzinfo=gettz(str(indate.tzinfo)))
This PR fixes this this blocking call. I also refactored some code pieces to get rid of some lifting warnings...