By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,675 Members | 2,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,675 IT Pros & Developers. It's quick & easy.

com wrapper and threads

P: n/a
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):

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

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

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
self.Parent.Object.UseCom() # <--- this generates error

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?

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.