[python-win32] COM and threading
June Kim
juneaftn at gmail.com
Fri Jun 27 10:52:40 CEST 2008
Running the following code results in an attribute error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python25\lib\threading.py", line 486, in __bootstrap_inner
self.run()
File "testcom.py", line 10, in run
print self.ie.locationUrl
File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 500, in
__getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: InternetExplorer.Application.locationUrl
It seems like the COM object isn't properly passed to the new thread.
Any roundabouts?
#testcom.py
from win32com.client import *
import pythoncom
import time, threading, sys
class Work(threading.Thread):
def run(self):
pythoncom.CoInitialize()
print self.ie.locationUrl
pythoncom.CoUninitialize()
ie=DispatchEx("InternetExplorer.Application")
ie.Navigate("http://www.google.com")
while ie.Busy:
time.sleep(0.1)
print ie.locationUrl
w=Work()
w.ie=ie
w.start()
w.join()
More information about the python-win32
mailing list