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

backends.winrt: add allow_sta() utility function #1567

Merged
merged 2 commits into from
May 7, 2024
Merged

Conversation

dlech
Copy link
Collaborator

@dlech dlech commented May 7, 2024

We had lots of users reporting issues with the WinRT backend hanging forever when trying to connect to a device. This was happening because some other imported library was initializing the the main thread to STA which caused some async callback to never be called.

To work around this, we added a check to make sure the main thread is set to MTA rather than STA. Unfortunately, in cases where there is a graphical user interface library being used AND that library is properly interated with asynco so that Bleak runs in the main thread rather than in a background thread, the thread type does need to be STA for the GUI to work. So in those very specific conditions, we need to not raise an exception.

We don't know of a way to detect this automatically, so we added a new utility function allow_sta() that the user can call to allow Bleak to run in an STA thread.

dlech added 2 commits May 7, 2024 15:23
We had lots of users reporting issues with the WinRT backend hanging
forever when trying to connect to a device. This was happening because
some other imported library was initializing the the main thread to STA
which caused some async callback to never be called.

To work around this, we added a check to make sure the main thread is
set to MTA rather than STA. Unfortunately, in cases where there is a
graphical user interface library being used AND that library is properly
interated with asynco so that Bleak runs in the main thread rather than
in a background thread, the thread type does need to be STA for the GUI
to work. So in those very specific conditions, we need to not raise an
exception.

We don't know of a way to detect this automatically, so we added a new
utility function `allow_sta()` that the user can call to allow Bleak to
run in an STA thread.
@dlech dlech linked an issue May 7, 2024 that may be closed by this pull request
@dlech dlech merged commit b9cded2 into develop May 7, 2024
14 checks passed
@dlech dlech deleted the winrt-allow-sta branch May 7, 2024 20:56
@dlech dlech restored the winrt-allow-sta branch May 7, 2024 20:56
@dlech dlech deleted the winrt-allow-sta branch May 7, 2024 21:04
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.

Add option to supress thread is not MTA exception
1 participant