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

Add asyncio thread safety docs #2171

Merged
merged 26 commits into from
May 14, 2024

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented May 14, 2024

Proposed change

Add asyncio thread safety docs.

Since introducing the thread safety checks in 2024.5, I've been watching for matching GitHub issues. Some changes to custom components refer to these checks as "undocumented breaking changes" in Home Assistant. These comments show that developers need help understanding asyncio concepts and thread safety. If they do not realize they have been using the wrong APIs or doing unsafe thread operations and think the check is a breaking change, they may likely create new non-thread-safe operations.

I've also seen some custom components bypass the checks by switching to asyncio.ensure_future or calling loop.create_task directly, which sadly makes the problem worse because the unsafe operation is now harder to find, and users end up reporting crashes that are hard to link to the component.

We should help them determine which API calls should replace the non-thread-safe call to increase the chance the issues will get solved and make developing for Home Assistant easier.

Type of change

  • Document existing features within Home Assistant
  • Document new or changing features which there is an existing pull request elsewhere
  • Spelling or grammatical corrections, or rewording for improved clarity
  • Changes to the backend of this documentation
  • Removed stale or deprecated documentation

Additional information

@bdraco bdraco marked this pull request as ready for review May 14, 2024 04:00
docs/asyncio_thread_safety.md Outdated Show resolved Hide resolved
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks, @bdraco 👍

../Frenck

@frenck frenck merged commit 12b4fca into home-assistant:master May 14, 2024
4 checks passed
@bdraco
Copy link
Member Author

bdraco commented May 14, 2024

Thanks. It's already being used by custom component devs.

@bdraco bdraco deleted the asyncio_thread_safety branch May 14, 2024 22:05
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.

None yet

4 participants