HI all,
I have a problem in accesing COM objects in threads. To be precise,
lets assume that I have a class GenericFunction s which is defined as
follows:
import win32com.client , pythoncom, thread
ie=win32com.cli ent.Dispatch('i nternetexplorer .application')
ie.Visible=1
class GenericFunction s:
def __init__(self):
print "In Constructor of Generic Functions"
def MyNavigate(self ,dest):
ie.Navigate(des t)
Now there is another file Main.py which is defined as follows:
import win32com.client , pythoncom, thread
from GenericFunction s import *
obj = GenericFunction s()
class Mainclass:
def __init__(self);
print "In Constructor of Main class"
def threadFunction( self,dest):
pythoncom.CoIni tialize()
d=pythoncom.CoG etInterfaceAndR eleaseStream(s,
pythoncom.IID_I Dispatch)
my_ie=win32com. client.Dispatch (d)
obj.func(dest) # this is gving an error.
pythoncom.CoUni nitialize()
if __name__ == "__main__":
s=pythoncom.CoM arshalInterThre adInterfaceInSt ream(pythoncom. IID_IDispatch,i e)
thread.start_ne w_thread(self.n av, (s,'www.google. com')
Basically, I want to access object of GenericFunction s class inside
threadFunction( ). However I was able to execute
my_ie.Navigate( "google.com "). But that was not I wanted. I am not
knowing where the error is....
Please let me know the solution ASAP...
Teja.P
I have a problem in accesing COM objects in threads. To be precise,
lets assume that I have a class GenericFunction s which is defined as
follows:
import win32com.client , pythoncom, thread
ie=win32com.cli ent.Dispatch('i nternetexplorer .application')
ie.Visible=1
class GenericFunction s:
def __init__(self):
print "In Constructor of Generic Functions"
def MyNavigate(self ,dest):
ie.Navigate(des t)
Now there is another file Main.py which is defined as follows:
import win32com.client , pythoncom, thread
from GenericFunction s import *
obj = GenericFunction s()
class Mainclass:
def __init__(self);
print "In Constructor of Main class"
def threadFunction( self,dest):
pythoncom.CoIni tialize()
d=pythoncom.CoG etInterfaceAndR eleaseStream(s,
pythoncom.IID_I Dispatch)
my_ie=win32com. client.Dispatch (d)
obj.func(dest) # this is gving an error.
pythoncom.CoUni nitialize()
if __name__ == "__main__":
s=pythoncom.CoM arshalInterThre adInterfaceInSt ream(pythoncom. IID_IDispatch,i e)
thread.start_ne w_thread(self.n av, (s,'www.google. com')
Basically, I want to access object of GenericFunction s class inside
threadFunction( ). However I was able to execute
my_ie.Navigate( "google.com "). But that was not I wanted. I am not
knowing where the error is....
Please let me know the solution ASAP...
Teja.P
Comment