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 option to supress thread is not MTA exception #1565

Closed
dlech opened this issue May 7, 2024 · 4 comments · Fixed by #1567
Closed

Add option to supress thread is not MTA exception #1565

dlech opened this issue May 7, 2024 · 4 comments · Fixed by #1567

Comments

@dlech
Copy link
Collaborator

dlech commented May 7, 2024

Although, using the workaround from the troubleshooting docs might break Kivy if Kivy needs the main thread to be STA for the UI.

So we might need to add an option to avoid the exception in cases like this.

Originally posted by @dlech in #1564 (reply in thread)

If Bleak is integrated with a UI framework that has proper asyncio integration, we need to be able to avoid this exception.

@dlech dlech linked a pull request May 7, 2024 that will close this issue
@dlech dlech mentioned this issue May 7, 2024
@MarkusPiotrowski
Copy link

@dlech
Let me start by saying that I do not understand anything about STA or MTA and what the exact reason was to introduce this "not MTA" BleakError.

However, .... if I understand correctly what you write above, this breaks Kivy (?), it breaks BeeWare (!, just tested by me) and it breaks other GUIs like tkinter although the asyncio integration might be done properly.
So, there is some code around breaking and needing a somewhat ugly (sorry) import switch that wasn't needed before.

I cannot judge what was worse, the situation before 0.22 or after 0.21. From my own perspective I would say: Please, revert this change. Or find a solution that does not break major Python frameworks by default.

@dlech
Copy link
Collaborator Author

dlech commented May 21, 2024

what the exact reason was to introduce this "not MTA" BleakError.

There have been at least half a dozen long standing issues of Bleak just locking up on Windows. We finally figured this out was due to importing packages with unwanted side effects. This was the best way I could figure out how to detect those unwanted side effects. But I'm not really happy with the result either. I did not expect very many people to be using Bleak with GUI's on Windows though, but maybe I was wrong!

Or find a solution that does not break major Python frameworks by default.

Open to suggestions here. For example, is there a way to detect if an app is running via BeeWare at runtime?

@MarkusPiotrowski
Copy link

I asked the BeeWare authors, waiting for an answer. Actually, BeeWare is a set of different tools and libraries, the GUI part is called "toga".

I read through #1132 and realized that this is a Win 11 issue. So you could possibly lift the burden from Win 10 users? Also, how about downgrading the exception to a warning?

@MarkusPiotrowski
Copy link

I got an answer from Russell Keith-Magee (@freakboy3742), the 'boss' of the BeeWare project:

Any "am I running in Toga" runtime check that I can think of would involve trying to import toga and then checking if toga.App.app exists. If it does, a Toga app has been created; it won't necessarily be running yet, though (and it might have terminated)
AIUI, the STA requirement is needed for Winforms to operate correctly. If I've misunderstood that requirement, I'm happy to entertain fixes.

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 a pull request may close this issue.

2 participants