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

Avoid blocking operations in event loop #145

Merged

Conversation

N3rdix
Copy link
Contributor

@N3rdix N3rdix commented Sep 22, 2024

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...

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

Successfully merging this pull request may close these issues.

2 participants