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

calls from other threads fallback for _winrt.py #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions win32more/_winrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
parse_arguments,
windll,
)
from win32more import asyncui
from win32more.asyncui import async_callback, asyncgen_callback
from win32more.Windows.Win32.Foundation import (
E_FAIL,
Expand Down Expand Up @@ -139,7 +140,14 @@ def ComPtr_as(self, cls):
instance = cls(own=True)
hr = self.QueryInterface(pointer(iid), pointer(instance))
if FAILED(hr):
raise WinError(hr)
if hr == -2147417842:
def threadsafe():
hr = self.QueryInterface(pointer(iid), pointer(instance))
if FAILED(hr):
raise WinError(hr)
asyncui.running_loop.call_soon_threadsafe(threadsafe)
else:
raise WinError(hr)
return instance


Expand Down Expand Up @@ -608,7 +616,14 @@ def __call__(self, this, *args, **kwargs):
cargs.append(pointer(result))
hr = self.delegate(this, *cargs)
if FAILED(hr):
raise WinError(hr)
if hr == -2147417842:
def threadsafe():
hr = self.delegate(this, *cargs)
if FAILED(hr):
raise WinError(hr)
asyncui.running_loop.call_soon_threadsafe(threadsafe)
else:
raise WinError(hr)
for callback in calllater:
callback()
return self.make_result(result)
Expand Down Expand Up @@ -803,7 +818,17 @@ def _ro_activate_instance(classid: str) -> IInspectable:
instance = IInspectable(own=True)
hr = factory.ActivateInstance(instance)
if FAILED(hr):
raise WinError(hr)
if hr == -2147417842:
def threadsafe():
hr = factory.ActivateInstance(instance)
if FAILED(hr):
WindowsDeleteString(hs)
raise WinError(hr)
asyncui.running_loop.call_soon_threadsafe(threadsafe)
else:
WindowsDeleteString(hs)
raise WinError(hr)
WindowsDeleteString(hs)
return instance


Expand Down