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

QWindowsContext: OleInitialize() failed: "COM error 0xffffffff80010106 RPC_E_CHANGED_MODE (Unknown error 0x080010106)" #423

Closed
edward-jw-yu opened this issue Jan 16, 2021 · 10 comments
Assignees
Labels
Backend: WinRT Issues or PRs relating to the WinRT backend GUIs Problems related to using GUI frameworks with Bleak

Comments

@edward-jw-yu
Copy link

edward-jw-yu commented Jan 16, 2021

  • bleak version: 0.9.1
  • Python version: 3.7
  • Operating System: win10
  • BlueZ version (bluetoothctl -v) in case of Linux:

Description

I am using bleak in PyQt5 projects on win10
and after import bleak, the console printed 'QWindowsContext: OleInitialize() failed: "COM error 0xffffffff80010106 RPC_E_CHANGED_MODE (Unknown error 0x080010106)"' when runing the PyQt5 project.
This caused my program failed to open the QFiledialog with Native windows. The program just hanged there like dead.

What I Did

Missing MWE
@hbldh
Copy link
Owner

hbldh commented Jan 18, 2021

I cannot help you much here, given that I never tried using Qt with Bleak. But I expect that it does not play nice with asyncio. Try integrating with qasync to make it work.

@hbldh hbldh self-assigned this Jan 18, 2021
@edward-jw-yu
Copy link
Author

Thank you

@JBrakefield
Copy link

JBrakefield commented Jun 18, 2021

I have this same issue happening now after reverting from Python 3.9 to Python 3.8. I get this same annoying warning if PyQt5 and bleak are both imported. My program ran fine on Python 3.9, but when trying to share my program and get the modules installed for someone else it was too difficult (pynnet installation issues and so forth). I can't remember how to get around them for python 3.9, and it is so much simpler to just use python 3.8 to get around that. However, this new warning/error is seemingly impossible to fix. I've tried everything including suppressing it with 'warnings' module (didn't work).

To summarize, the issue is not with asyncio but with PyQt5 and Bleak imports specifically. It occurs after app = QApplication(sys.argv) is called. I can find no way around this.

We either need a fix for this issue or a way to make things install more smoothly with python 3.9.

@dlech
Copy link
Collaborator

dlech commented Jun 18, 2021

Related issue (for pywinrt backend): microsoft/xlang#690

I think the solution is probably to make sure Qt calls and Bleak calls each stay on their own thread.

@dlech
Copy link
Collaborator

dlech commented Jun 25, 2021

Also see #580 (comment) for another possible workaround.

@JBrakefield
Copy link

JBrakefield commented Jun 25, 2021

Also see #580 (comment) for another possible workaround.

I tried adding

from winrt import _winrt

_winrt.unint_apartment()

but python says "AttributeError: module 'winrt._winrt' has no attribute 'unint_apartment'"

@dlech
Copy link
Collaborator

dlech commented Jun 25, 2021

Looks like I spelled "uninit" wrong.

@JBrakefield
Copy link

ahh thanks! I think this fixed it!

@hbldh hbldh added Backend: WinRT Issues or PRs relating to the WinRT backend GUIs Problems related to using GUI frameworks with Bleak labels Jun 28, 2021
@bstarbuck3
Copy link

from bleak_winrt import _winrt
_winrt.uninit_apartment()

@dlech
Copy link
Collaborator

dlech commented Jan 26, 2022

FYI, this workaround is no longer needed since Bleak v0.14.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: WinRT Issues or PRs relating to the WinRT backend GUIs Problems related to using GUI frameworks with Bleak
Projects
None yet
Development

No branches or pull requests

5 participants