com wrapper and threads

M

mic

I'm playing with using COM object shared among different threads.
Unfortunately I've come into a problem - I don't know how to properly invoke
com object from external thread. Here comes simplified code I'd like to use:

class ComObjectWrapper:
#this class is by all means needed - of course it's code is much more
complicated than just simply wrapping the COM interface
def __init__(self):
self.ComObject = Dispatch(somecom)

def useCom(self, value):
self.ComObject.use(value)

class MainThread:
def __init__(self):
self.Object = ComObjectWrapper()

def runChildThread(self):
CThread = ChildThread(self)
CThread.start()

class ChildThread(Thread):
def __init__(self, parent):
self.Parent = parent

def run(self):
#This thread has to use some methods from ComObjectWrapper instance
and it's dispatched COM object
pythoncom.CoInitialize()
self.Parent.Object.UseCom() # <--- this generates error
pythoncom.CoUninitialize()

I was trying to use different combinations of sys.coinit_flags = 0 and
pythoncom.COINIT_MULTITHREADED but without success up till now. I've even
managed to send to child thread proper com reference by using stream
marshalling (as stated in "Python programming for win32"), but still I don't
want to use COM itself but its "wrapper" class. Any enlightening thoughts?

Michal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top