所以,我有这个下面的代码片段,它试图通过WIN32API启动微软Powerpoint:如何启动在单独的线程Win32应用程序在Python
import threading
import win32com.client
import sys
class myDemo(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
try:
myObject = win32com.client.Dispatch("Powerpoint.Application")
print "OK"
except:
print "Failed to start Powerpoint!"
sys.exit(1)
print "Now attempting to shutdown..."
try:
myObject.quit()
except:
print "Error"
if __name__ == "__main__":
test = myDemo()
test.start()
的问题是,它失败,我不知道为什么。 但是,如果我将最后一行更改为test.run()
,它将成功启动。 那么为什么这个失败与test.start()
?
为什么会发生这种情况,我应该如何解决这个问题?考虑到我需要Powerpoint在异步线程上异步运行?
在此先感谢。
编辑:显然,我的问题是不知何故与此相关的:http://python.6.x6.nabble.com/Dispatch-error-CoInitialize-has-not-been-called-td1951088.html
但是从提出妥善的解决办法分开,似乎没有人回答到底为什么COM是表现这种方式。
“开始”是什么意思?你的对象只有一个方法,“运行” –
start()异步执行对象的运行方法。 – kstratis