com wrapper and threads

Discussion in 'Python' started by mic, Feb 4, 2004.

  1. mic

    mic Guest

    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
     
    mic, Feb 4, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yoda
    Replies:
    2
    Views:
    478
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  2. threads without threads

    , Aug 27, 2004, in forum: C Programming
    Replies:
    4
    Views:
    446
    William Ahern
    Aug 27, 2004
  3. Pedro Pinto

    Java Threads - Get running threads

    Pedro Pinto, Apr 8, 2008, in forum: Java
    Replies:
    2
    Views:
    1,519
    Arne Vajhøj
    Apr 9, 2008
  4. Une bévue
    Replies:
    0
    Views:
    185
    Une bévue
    Jun 14, 2006
  5. John Tsiombikas

    Trivial C11 threads.h wrapper (public domain)

    John Tsiombikas, Sep 27, 2012, in forum: C Programming
    Replies:
    37
    Views:
    2,085
    Shao Miller
    Dec 15, 2012
Loading...

Share This Page