Skip to content

Block pyserial-asyncio in favor of pyserial-asyncio-fast#116635

Draft
bdraco wants to merge 14 commits intodevfrom
block_pyserial_asyncio
Draft

Block pyserial-asyncio in favor of pyserial-asyncio-fast#116635
bdraco wants to merge 14 commits intodevfrom
block_pyserial_asyncio

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented May 2, 2024

needs

previous issue reports

Proposed change

pyserial-asyncio does blocking I/O (actually its a sleep, but falls under the same class of issue) in asyncio loop and is not maintained

I'm hoping we have removed all usage at this point, but if not, this PR will fail

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

pyserial-asyncio does blocking I/O in asyncio loop and is not maintained
@home-assistant home-assistant Bot added cla-signed core small-pr PRs with less than 30 lines. labels May 2, 2024
This may not be possible yet, but the long term goal is to get
rid of pyserial-asyncio everywhere so we can prevent future
integrations from using it and than we have to go though the
effort of getting them to replace it with pyserial-asyncio-fast
to avoid the event loop being blocked

needed for #116635
@bdraco bdraco mentioned this pull request May 2, 2024
20 tasks
balloob
balloob previously approved these changes May 3, 2024
@andriej
Copy link
Copy Markdown
Contributor

andriej commented May 16, 2024

I have issue with OpenTherm (OTGW) integration - there are no open issues regarding that integration. It uses socket:// to connect to gateway and I see warning in logfile:
2024-05-16 15:30:33.962 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to sleep inside the event loop by integration 'config' at homeassistant/components/config/config_entries.py, line 120: await hass.config_entries.async_reload(entry_id) (offender: /usr/local/lib/python3.12/site-packages/serial/urlhandler/protocol_socket.py, line 104: time.sleep(0.3)), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+config%22

I do not see any other errors regarding OpenTherm. Only informational that it can't connect to socket:// in UI.
It was working all releases before 2024.5.
It seems to be issue with pyserial that's mentioned here? Shall I create separate bugreport?

@bdraco
Copy link
Copy Markdown
Member Author

bdraco commented May 16, 2024

I was under the impression it was fixed in 2024.5.1 via #116527. If there is still a problem, please open a new issue report.

@andriej
Copy link
Copy Markdown
Contributor

andriej commented Jun 5, 2024

New version of HA has more detailed info. It seems that issue is connected not directly with OTGW I've mentioned but pysocket in 'config' part of HA core.

Detected blocking call to sleep inside the event loop by integration 'config' at homeassistant/components/config/config_entries.py, line 120: await hass.config_entries.async_reload(entry_id) (offender: /usr/local/lib/python3.12/site-packages/serial/urlhandler/protocol_socket.py, line 104: time.sleep(0.3)), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+config%22 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 223, in 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 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, 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/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request resp = await request_handler(request) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle resp = await handler(request) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 210, in forwarded_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware response = await handler(request) File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle result = await handler(request, **request.match_info) File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 120, in post await hass.config_entries.async_reload(entry_id)

@bdraco
Copy link
Copy Markdown
Member Author

bdraco commented Aug 16, 2024

Looks like have one more https://www.home-assistant.io/integrations/epson

@emontnemery emontnemery requested a review from balloob August 21, 2024 11:28
@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions Bot added the stale label Oct 20, 2024
@bdraco bdraco removed the stale label Oct 20, 2024
This was referenced Dec 19, 2025
denpamusic added a commit to denpamusic/PyPlumIO that referenced this pull request Jan 7, 2026
While this is not strictly related to PyPlumIO as a standalone project, I belive it's beneficial for it as well.

See: https://developers.home-assistant.io/blog/2026/01/05/pyserial-asyncio-fast
See: home-assistant/core#116635
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants