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

how to call async udf with sheet as parameter? #2420

Open
jerronl opened this issue Mar 16, 2024 · 0 comments
Open

how to call async udf with sheet as parameter? #2420

jerronl opened this issue Mar 16, 2024 · 0 comments

Comments

@jerronl
Copy link
Contributor

jerronl commented Mar 16, 2024

OS (e.g. Windows 10 or macOS Sierra)

win10

Versions of xlwings, Excel and Python (e.g. 0.11.8, Office 365, Python 3.7)

xlwings 0.30.13
office pro plus 2016 version 2402
python 3.11.5

Describe your issue (incl. Traceback!)

@xw.func  # (async_mode="threading")
@xw.arg("sheet1", vba="Sheet1")
def test1(sheet1):
    print("test1", sheet1.Name)


@xw.func(async_mode="threading")
@xw.arg("sheet1", vba="Sheet1")
def test2(sheet1):
    print("test2", sheet1.Name)


test1 test
async_thread failed
Traceback (most recent call last):
  File "d:\ProgramData\miniconda3\envs\s1\Lib\site-packages\xlwings\udfs.py", line 67, in async_thread_nocaller
    await loop.run_in_executor(com_executor, functools.partial(func, *args))
  File "d:\ProgramData\miniconda3\envs\s1\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\mydoc\git\trade\optai2.py", line 308, in test2
    print("test2", sheet1.Name)
                   ^^^^^^^^^^^
  File "d:\ProgramData\miniconda3\envs\s1\Lib\site-packages\win32com\client\__init__.py", line 583, in __getattr__
    return self._ApplyTypes_(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\ProgramData\miniconda3\envs\s1\Lib\site-packages\win32com\client\__init__.py", line 572, in _ApplyTypes_
    self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pywintypes.com_error: (-2147417842, 'The application called an interface that was marshalled for a different thread.', None, None)

Include a minimal code sample to reproduce the issue (and attach a sample workbook if required!)

# Your code here
Sub test()
    XLPy.CallUDF "test", "test1", Array(shtTest)
    XLPy.CallUDF "test", "test2", Array(shtTest)
End Sub
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

No branches or pull requests

1 participant