пробую обращаться к ИЕ через com интерфейс напрямую
import threading, time
from win32com.client import Dispatch
import time,threading,pythoncom,sys
stopEvent=threading.Event()
def waitUntilReady(ie):
if ie.ReadyState!=4:
while 1:
pythoncom.PumpWaitingMessages()
stopEvent.wait(.2)
if stopEvent.isSet() or ie.ReadyState==4:
stopEvent.clear()
break;
class myThread(threading.Thread):
def __init__(self, func):
threading.Thread.__init__(self)
self.keepRunning = True
self.func = func
def run(self):
while self.keepRunning:
self.func()
self.keepRunning = False
def stop(self):
self.keepRunning = False
if __name__ == '__main__':
class MyCLass():
def __init__(self):
self.ie=Dispatch('InternetExplorer.Application')
self.ie.Visible=1
self.ie.Navigate("http://www.google.com")
def go(self):
pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)
self.ie.Navigate('www.yandex.ru')
def tt (self):
self.t = myThread(self.go)
self.t.start()
c = MyCLass()
c.tt()
выдает ошибку:
Traceback (most recent call last):
File “C:\python26_64\lib\threading.py”, line 525, in __bootstrap_inner
self.run()
File “<module9>”, line 31, in run
File “<module9>”, line 54, in go
File “C:\python26_64\lib\site-packages\win32com\gen_py\EAB22AC0-30C1-11CF-A7EB-0000C05BAE0Bx0x1x1.py”, line 1213, in Navigate
, Flags, TargetFrameName, PostData, Headers)
com_error: (-2147417842, ‘The application called an interface that was marshalled for a different thread.’, None, None)
я так понимаю, это происходи из-за того,что я пытаюсь вызвать обьект,который был создан в другом потоке…
можно как -то это обойти?)