Python多线程COM对象
我有3个python模块 main.py client.pyPython多线程COM对象,python,python-multithreading,win32com,Python,Python Multithreading,Win32com,我有3个python模块 main.py client.py class Formatter: def __init__(self): self._excel = win32.dynamic.Dispatch('Excel.Application') def format_excel(self, info_list): pythoncom.CoInitialize() self._excel.Workbooks.Add()
class Formatter:
def __init__(self):
self._excel = win32.dynamic.Dispatch('Excel.Application')
def format_excel(self, info_list):
pythoncom.CoInitialize()
self._excel.Workbooks.Add()
# other codes
interface.py
py是一个Qt UI模块,因此它没有任何与此问题相关的内容
main.py导入interface.py和client.py类,并执行程序的主要功能
client.py是所有核心功能所在的核心模块
client.py(format_excel function)中的一个函数是调用win32com.client来执行excel操作,它将根据给定的输入修改excel的输出
这里的问题是当我在main.py中启动一个线程来运行client.py(format\u excel函数)中的函数时,它给了我这样的错误
应用程序调用了为不同线程封送的接口
我的代码如下(简化)
client.py
class Formatter:
def __init__(self):
self._excel = win32.dynamic.Dispatch('Excel.Application')
def format_excel(self, info_list):
pythoncom.CoInitialize()
self._excel.Workbooks.Add()
# other codes
main.py
self.\u数据包含一些从GUI获取的信息,因此我没有添加到代码段中
class Main:
def __init__(self):
self._format = Formatter()
self._data = []
def start(self):
t = threading.Thread(target=self._format.format_excel, args=[self._data])
t.start()
# other codes
这里需要一些帮助。可能是通读的副本,但我不太明白,任何帮助都会有用。。