com wrapper and threads

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mic

    com wrapper and threads

    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 ComObjectWrappe r:
    #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(someco m)

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

    class MainThread:
    def __init__(self):
    self.Object = ComObjectWrappe r()

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

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

    def run(self):
    #This thread has to use some methods from ComObjectWrappe r instance
    and it's dispatched COM object
    pythoncom.CoIni tialize()
    self.Parent.Obj ect.UseCom() # <--- this generates error
    pythoncom.CoUni nitialize()

    I was trying to use different combinations of sys.coinit_flag s = 0 and
    pythoncom.COINI T_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


Working...