【发布时间】:2021-07-16 08:17:00
【问题描述】:
我试图让它在我运行一个函数时我的 GUI 不会冻结,所以我把它放到一个线程中,但是当我将它用作一个线程时,我得到了以下错误;
错误:
- pywintypes.com_error: (-2147417842, '应用程序调用了为不同线程编组的接口。', 无, 无)
我目前正在使用 xlwings 在 SaveRunThread 函数中使用 excel 表做一些事情
import xlwings as xw
def SaveRun(self):
try:
saverun = threading.Thread(target=self.SaveRunThread)
saverun.start()
except:
print('Not Run')
def SaveRunThread(self):
'Save Run File to directory'
try:
app = xw.App(visible=False)
book = xw.Book(r'{0}\Template_VS.xlsx'.format(TemplateDirectory[-1]))
### Do something
book.save(r'{0}\{1}.xlsx'.format(newDirectory[-1], nameList[-1]))
app.kill() #####Error occurs here
except:
print('Not Run')
我希望它在调用时运行代码而不冻结 GUI。我现在没有 MCVE,所以我只发布了部分代码。
【问题讨论】:
-
您使用的是什么版本的 xlwings?
-
@FelixZumstein 我正在使用当前版本:0.15.8
标签: python-3.x python-multithreading xlwings